/** * This SWFAddress class is an instanciable version of the original SWFAddress class used for deep linking in Flash. * * This class is inspired from the original AS3 SWFAddress class written by Rostislav Hristov (http://www.asual.com/swfaddress/) * * @author PingooO (http://pingooo.net) * @version 1.1 */ package { import flash.external.ExternalInterface; import flash.events.Event; import flash.events.EventDispatcher; public class SWFAddress extends EventDispatcher { private var _value:String = ''; /** * Creates a new SWFAddress instance. * After creating the instance, add an EventListener on the CHANGE event to be noticed when the hash of the navigator's URI changes. */ public function SWFAddress() { if (ExternalInterface.available) { ExternalInterface.addCallback('getSWFAddressValue', function():String {return _value}); ExternalInterface.addCallback('setSWFAddressValue', valueChanged); } else trace("error with ExternalInterface"); } private function valueChanged(val:String) { dispatchEvent(new Event(Event.CHANGE)); } /** * The title of the navigator window */ public function get title():String { var val:String = String(ExternalInterface.call('SWFAddress.getTitle')); if (val == 'undefined' || val == null) val = ''; return val; } public function set title(val:String):void { ExternalInterface.call('SWFAddress.setTitle', val); } /** * The status string of the navigator */ public function get status():String { var val:String = String(ExternalInterface.call('SWFAddress.getStatus')); if (val == 'undefined' || val == null) val = ''; return val; } public function set status(val:String):void { ExternalInterface.call('SWFAddress.setStatus', val); } /** * Resets the status string of the navigator */ public function resetStatus():void { ExternalInterface.call('SWFAddress.resetStatus'); } /** * The path of the current URI (without the parameters) */ public function get path():String { var val:String = value; if (val.indexOf('?') != 1) { return val.split('?')[0]; } else { return val; } } /** * The query string of the current URI (the parameters) */ public function get queryString():String { var val:String = value; var index:Number = val.indexOf('?'); if (index != -1 && index < val.length) { return val.substr(index + 1); } return ''; } /** * Return the value of the param parameter * @param param The name of the parameter * @return The value of the parameter */ public function getParameter(param:String):String { var val:String = value; var index:Number = val.indexOf('?'); if (index != -1) { val = val.substr(index + 1); var params:Array = val.split('&'); var p:Array; var i:Number = params.length; while (i--) { p = params[i].split('='); if (p[0] == param) { return p[1]; } } } return ''; } /** * An array of the names of the parameters */ public function get parameterNames():Array { var val:String = value; var index:Number = val.indexOf('?'); var names:Array = new Array(); if (index != -1) { val = val.substr(index + 1); if (val != '' && val.indexOf('=') != -1) { var params:Array = val.split('&'); var i:Number = 0; while (i < params.length) { names.push(params[i].split('=')[0]); i++; } } } return names; } /** * The value of the hash of the URI (after the #); */ public function get value():String { var addr = String(ExternalInterface.call('SWFAddress.getValue')); var id = String(ExternalInterface.call('SWFAddress.getId')); if (addr == 'undefined' || addr == null) addr = ''; return addr; } public function set value(val:String):void { if (val == 'undefined' || val == null) val = ''; _value = val; ExternalInterface.call('SWFAddress.setValue', val); } } }