Skip to main content
Samuel Lockyer
Inspiring
November 28, 2011
Answered

How do you stop all the code until an event has fired?

  • November 28, 2011
  • 1 reply
  • 1117 views

First, I'm really sorry for the newbie question, but my book as useful as licking a toilet clean.

I am attempting to load a song in every iteration (of a loop), extract information (like id3 tags) and then move on to another song; but, I need event listeners to tell me when the song has loaded. So how do I stop the progress of the loop until the events have complete?

Thanks.

This topic has been closed for replies.
Correct answer Ned Murphy

You do not use a 'for' (or similar) loop if that is what you are doing.  You create a functional loop where the completion of one series of executions ends with callings the start of the next set of executions.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
November 28, 2011

You do not use a 'for' (or similar) loop if that is what you are doing.  You create a functional loop where the completion of one series of executions ends with callings the start of the next set of executions.

Samuel Lockyer
Inspiring
November 28, 2011

I thought it might have something to do with a recursive function. Thanks, I can probably work it out from here.

Ned Murphy
Legend
November 28, 2011

You're welcome.  It would not be so much a recursive function as a looping set of functions, here's a rough outline...

var filenames:Array = .... array with filenames

var itemCount = 0;

function loadSomething(){

     loadSomeFile(filenames[itemCount])

     addEventListener(Event.COMPLETE, processFile)

}

function processFile(evt){

     //process whatever relative to the loaded file, then

     itemCount++;

     if(itemCount < filenames.length) loadSomething();

}