php - How to Get Array From URL Encoded String? -
i'm sure easy thing couldn't find in google hours. i'm new actionscript , i'm trying obtain array of variables string generated .php file.
my php file outputs this:
var1=42&var2=6&var3=string
and actionscript code is:
public function callajax_variables(url:string , the_array:array) { var request:urlrequest = new urlrequest(url); var variables:urlloader = new urlloader(); variables.dataformat = urlloaderdataformat.variables; variables.addeventlistener(event.complete, variables_complete_handler(the_array)); try { variables.load(request); } catch (error:error) { trace("unable load url: " + error); } } function variables_complete_handler(the_array:array):function { return function(event:event):void { var loader:urlloader = urlloader(event.target); //the_array = loader.data; // doesn't work. //the_array = urlvariables.decode(loader); // doesn't work either. //trace(loader.data['var1']); // outputs 42, i'm getting string php. }; }
i think understood but, in end, want have array (in actionscript) give me:
the_array['var1']=42; the_array['var2']=6; the_array['var3']="string";
what doing wrong? should do? thanks!
edit: i'm trying variables php actionscript. e.g. php file correctly converts array html query, don't know how parse them in array in actionscript.
you should use urlvariables
this.
var vars:urlvariables = new urlvariables(e.target.data);
this way can say:
trace(vars.var2); // 6
an array useless here result associative rather index based, though can take values , throw them array simple loop:
var array:array = []; for(var i:string in vars) { array.push(vars[i]); }
Comments
Post a Comment