Can someone please help me with this? I am trying to wait for and Event.COMPLETE in another class but my code just jumps through the event listener and executes the following code without waiting for the event to complete so my variable is not being set. This is the code snippet:
private function init():void{
vidName=new VidArray();//create object
//I want the code to wait here until the event Completes then return "videoName"
vidName.loader.addEventListener(Event.COMPLETE,vidName.handlerComplet e);//it is getting to handlerComplete in VidArray
videoToPlay=vidName.videoName;
trace("videoToPlay is = ", videoToPlay);//returns NULL
}
If you mean that the following two lines are being executed
videoToPlay=vidName.videoName;
trace("videoToPlay is = ", videoToPlay);//returns NULL
THat is what will happen. Assigning an event listener does not cause code to stop processing. The listener is assigned and the processing immediately moves on to the code after the assignment. If you want that code to wait until after the event occurs then you need to trigger it in the handlerComplete function
Yes, I did know that it would not hold the execution of the code but I just don't seem to be able to hold the code to set the variable.This is my handlerComplete function:
private function handlerComplete(evt:Event):void
{
var loader:URLLoader=URLLoader(evt.target);
vids=loader.data.vids;
videoList=vids.split(";");
trace("the data has been loaded = ", videoList);
chooseVideo();
}
Should I put an if statement here or what? Thanks for your help.
North America
Europe, Middle East and Africa
Asia Pacific