PDA

View Full Version : Function not waiting for a line to finish working before moving on.


motiv8ed
01-19-2007, 06:01 PM
*UPDATE* sorry, put this in the wrong forum.. ment to put in actionscript 2.0 (but reply if you know the answer ;) )
public function send_Request(url1:String, uri:String){
var loadit_lv:LoadVars = new LoadVars();
loadit_lv.load(url1+uri);
loadit_lv.onData = function(data:String){
trace(data);
}
trace('Donee with function');
}

This function prints:

Donee with function
Text string from onData

Someone help me to understand why the last line of the function outputs before the .load method finishes executing?

red01
01-23-2007, 04:09 AM
because the onData only execuest when the data has been loaded.

so when you call the load it goes away and trys to find the data and transfer it, wiht the rest of the script executes, once the data has been loaded only then will the trade(data) be called