Skip navigation
Currently Being Moderated

listen for an event in another class

Aug 28, 2011 4:04 AM

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
                }

 
Replies
  • Currently Being Moderated
    Aug 28, 2011 5:22 AM   in reply to TezS56

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points