Return to Snippet

Revision: 44147
at April 7, 2011 01:59 by scottwatkins


Initial Code
/**
 * _getQuerystringAsObject
 * returns the URL querystring as an object
 */
private function _getQuerystringAsObject():Object
{
    var _params:Object = {};
    var _queryString:String;
    var _all:String;
	
    try 
    {
        _all =  ExternalInterface.call("window.location.href.toString");
        _queryString = ExternalInterface.call("window.location.search.substring", 1);
        if(_queryString)
	{
	    var params:Array = _queryString.split('&');
	    var length:uint = params.length;
	    for (var i:uint=0,index:int=-1; i<length; i++) 
	    {
	        var kvPair:String = params[i];
		if((index = kvPair.indexOf("=")) > 0)
		{
		    var key:String = kvPair.substring(0,index);
		    var value:String = kvPair.substring(index+1);
		    _params[key] = value;
		}
	    }
	}
    }catch(e:Error) { trace("ERROR"); }
    return _params;
}

Initial URL

                                

Initial Description
This function will take the querystring from the URL and return it as a property:value paired object.

Initial Title
Get Querystring as an Object

Initial Tags
actionscript

Initial Language
ActionScript 3