php - Whats wrong with this URLRequest or Loader? -


i have following code:

var myrequest:urlrequest = new urlrequest("http://localhost/example.com/scripts/get_peerid.php?peerid=" + myid.text); var myloader:urlloader = new urlloader(); myloader.dataformat = "urlloaderdataformat.variables"; myloader.load(myrequest); writetext(myloader.data); var vars:urlvariables = new urlvariables(myloader.data); writetext(vars.peerid); 

and get_peerid.php? gets displays:

peerid=5a00d01af308bb4261198d92a89b939979e7ea260a3ead7d49a9b6bdd0492b72 

however, writetext(vars.peerid) displays null. can't seem figure out why. ideas?

the urlloader class asynchronous. quote docs:

a urlloader object downloads of data url before making available code in applications. sends out notifications progress of download, can monitor through bytesloaded , bytestotal properties, through dispatched events.

so, way vars.peerid work directly after calling urlloader.load method if network has 0 latency , server side processing has 0 execution time. both, extremely unlikely.

instead should listen complete event.

var myrequest:urlrequest = new urlrequest("http://localhost/example.com/scripts/get_peerid.php?peerid=" + myid.text); var myloader:urlloader = new urlloader(); myloader.dataformat = "urlloaderdataformat.variables"; myloader.addeventlistener(event.complete,oncomplete); myloader.load(myrequest); 

then somewhere later in code, this:

public function oncomplete(event:event):void{  writetext(myloader.data);  var vars:urlvariables = new urlvariables(myloader.data);  writetext(vars.peerid); } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -