"pause" a for loop or a while loop until current action is completed? (Evant Dispatch?)
Posted on 2006-05-04
Ok, I read this article on Macromedia, err Adobe...it is a great article on the use of an Event Dispatcher to assign listeners for your custom events instead of running some sort of loop or interval to check over and over...Great concept and I know it works...
My quandry is using this methodology inside a loop (for or while, etc.).
Here's the deal. I am loading data into my Flash movie from XML. I load the XML file and loop through the nodes of the XML file and display my content as I loop through the XML object. Make sense?
the issue is that some of my content tells flash to load images or .swf files (using a loader class I have created/extended) as i go through. You may start to see my issue here...
I need to position other display elements based on the size and location of these loaded clips, but you can't get that data until it is completely loaded. In my class now I have an onLoadInit function that sets a value inside the class instance to true to say it's loaded. each time I load an image with this class, I immediately call create a unique setinterval id for each image that calls a function until the "loaded" value is true for ALL clips loaded then it executes another function to loop through all the elements and repostion them accordingly. This works great and fast right now, but I am not loading a lot of elements YET.
So back to the original story...it would be great to create event dispatch events and listeners for each element I am loading and then execute what I need to after that...
The ideal way would be to load the image, pause the loop until the listener receives the event dispatch event and then the rest of the loop executes thus allowing each element on stage to be positioned in order and from one loop through all the data instead of multiple loops.
So, can I do this? Can I "pause" the loop through the XML object to wait for each item to load so that all elements have thier properties before continuing to load the next and position everything the first time through?