Best way to find out when somethings loaded

Branching off from one of my previous posts about loading dynamic content up via a class. Im wondering whats the best way to find out when somethings loaded…

As actionscript is painfully asynchonous, it means that things done follow the traditional flow like you would expect things to load.

In most languages you would call a loading function then if it loaded do actionA or if it broke do ActionB. However due to the nature of async you never really know when somethings loaded until you get the onLoad() (or whatever you call yours) function called.

Now for simple globally accessable code this is fine as you can work around it with having global onLoad functions that will trigger something else, however when all the loading is contained within a class you havent got the luxury of being able to just call any function in/out of scope.

So how do you guys get around this? i mean a simple option that comes to mind is to flag a boolean as true when it loads internally of each class, however then you have the problem of you have to somehow get actionscript to enter a loop until it loads or dies. This method would typically mean you hold off doing anything in the code until whatever you are loading has given a response, although this basically means you are making your code synchronous.

An example would be loading a tileset system. You load your file which will contact an external file for information on what tileset and level to use. First of all you would need to load up this external file, then start loading up the tileset, once thats loaded you will want to load up the level using the tiles from the tileset. Then add the level to the scene to be displayed. Thinking a little bit down the line from here, what if you needed to load up a new level that the player is about to enter, you would have to keep the current tileset and level in memory and load another one ready for when the user enters this new area. Although the first part is the only thing i really need to do at the moment, the 2nd part may be something to look at later…

So thinking about it in a way that actionscript seems to have been designed for, there must be a way to have everything else loading while you load up some dynamic stuff on the fly and not stopping everything else. To be honest it all seems a little illogical to me, but im a novice when it comes to actionscript so could someone enlighten me on how the best way to do this sort of thing is progmatically without having to do crazy frame loops or anything.

As always any advice is appreciated!