The following examples show how you can parse URL encoded strings using ActionScript 2.0 and ActionScript 3.0.
Full code after the jump.
The following example shows how you can use the LoadVars class and the decode() method to parse a URL encoded string:
// ActionScript 2.0 var loadVars:LoadVars = new LoadVars(); loadVars.decode("firstName=Tom&lastName=Jones"); lbl.text = loadVars.lastName + "," + loadVars.firstName;
In ActionScript 3.0, you can use one of two methods. The first method passes the string to be decoded to the URLVariables class constructor:
// ActionScript 3.0 var urlVariables:URLVariables = new URLVariables("firstName=Tom&lastName=Jones"); lbl.text = urlVariables.lastName + "," + urlVariables.firstName;
The second method is similar to the ActionScript 2.0 approach and uses the decode() method to parse the URL encoded string:
// ActionScript 3.0 var urlVariables:URLVariables = new URLVariables(); urlVariables.decode("firstName=Tom&lastName=Jones"); lbl.text = urlVariables.lastName + "," + urlVariables.firstName;
{ 3 comments… read them below or add one }
Just a little correction
Very helpful….I was wondering how do you deal with name value pairs in URLVariable. Lets say I have an array of name value pairs.
Thanks
var urlVariables:URLVariables = new URLVariables(infoTxt.data);
must be
var urlVariables:URLVariables = new URLVariables(evt.target.data);