topical media & game development

talk show tell print

mashup-rmx-07-Chapter7-Exercise4-com-asual-swfaddress-SWFAddress.ax

mashup-rmx-07-Chapter7-Exercise4-com-asual-swfaddress-SWFAddress.ax (swf ) [ flash ] flex


  
SWFAddress v1.1: Deep linking for Flash - http://www.asual.com/swfaddress/ SWFAddress is (c) 2006 Rostislav Hristov and is released under the MIT License: http://www.opensource.org/licenses/mit-license.php

  
  
  package com.asual.swfaddress{
  
      import flash.external.ExternalInterface;
      import flash.utils.clearInterval;
      import flash.utils.setInterval;
  
      public class SWFAddress {
  
          private static var _value:String = '';
          private static var _availability:Boolean = ExternalInterface.available;
   
          public static var onChange:Function;
  
          private static function _check():void {
              if (SWFAddress.onChange != null) {
                  clearInterval(SWFAddress._interval);
                  if (_availability) {
                      ExternalInterface.addCallback('getSWFAddressValue', 
                          function():String {return _value});
                      ExternalInterface.addCallback('setSWFAddressValue', 
                          SWFAddress.setValue);
                  }
                  SWFAddress.setValue(SWFAddress.getValue());
              }
          }    
          private static var _interval:Number = setInterval(SWFAddress._check, 10);
  
          public static function getTitle():String {
              var title:String = (_availability) ? 
                  ExternalInterface.call('SWFAddress.getTitle') as String : '';
              if (title == 'undefined' || title == null) title = '';
              return title;
          }
  
          public static function setTitle(title:String):void {
              if (_availability) ExternalInterface.call('SWFAddress.setTitle', title);
          }
  
          public static function getStatus():String {
              var status:String = (_availability) ? 
                  ExternalInterface.call('SWFAddress.getStatus') as String : '';
              if (status == 'undefined' || status == null) status = '';
              return status;
          }
  
          public static function setStatus(status:String):void {
              if (_availability) ExternalInterface.call('SWFAddress.setStatus', status);
          }
          
          public static function resetStatus():void {
              if (_availability) ExternalInterface.call('SWFAddress.resetStatus');
          }
          
          public static function getPath():String {
              var value:String = SWFAddress.getValue();
              if (value.indexOf('?') != 1) {
                  return value.split('?')[0];
              } else {
                  return value;   
              }
          }
  
          public static function getQueryString():String {
              var value:String = SWFAddress.getValue();
              var index:Number = value.indexOf('?');
              if (index != -1 && index < value.length) {
                  return value.substr(index + 1);
              }
              return '';
          }
          
          public static function getParameter(param:String):String {
              var value:String = SWFAddress.getValue();
              var index:Number = value.indexOf('?');
              if (index != -1) {
                  value = value.substr(index + 1);
                  var params:Array = value.split('&');
                  var p:Array;
                  var i:Number = params.length;
                  while(i--) {
                      p = params[i].split('=');
                      if (p[0] == param) {
                          return p[1];
                      }
                  }
              }
              return '';
          }
  
          public static function getParameterNames():Array {
              var value:String = SWFAddress.getValue();
              var index:Number = value.indexOf('?');
              var names:Array = new Array();
              if (index != -1) {
                  value = value.substr(index + 1);
                  if (value != '' && value.indexOf('=') != -1) {            
                      var params:Array = value.split('&');
                      var i:Number = 0;
                      while(i < params.length) {
                          names.push(params[i].split('=')[0]);
                          i++;
                      }
                  }
              }
              return names;
          }
  
          public static function getValue():String {
              var addr:String, id:String = null;
              if (_availability) { 
                  addr = ExternalInterface.call('SWFAddress.getValue') as String;
                  id = ExternalInterface.call('SWFAddress.getId') as String;
              }
              if (id == null || !_availability) {
                  addr = SWFAddress._value;
              } else {
                  if (addr == 'undefined' || addr == null) addr = '';            
              }
              return addr;
          }
  
          public static function setValue(addr:String):void {
              if (addr == 'undefined' || addr == null) addr = '';
              SWFAddress._value = addr;
              if (_availability) ExternalInterface.call('SWFAddress.setValue', addr);
              if (SWFAddress.onChange != null) SWFAddress.onChange();
          }
      }
  }


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.