Loading external pngs into an AS2 swf that is loaded into an AS3 swf wrapper
- by James Fassett
I have a Wrapper SWF that loads a series of AS2 movies. Each AS2 movie loads a series of .png files.
AS3_wrapper.swf
|-> AS2_1.swf
|-> image_1.png
|-> image_2.png
|-> AS2_2.swf
|-> image_1.png
|-> image_2.png
Inside of the AS2 I listen for the load of the pngs using onLoadInit and update my UI.
This works fine for the first AS2 swf. But when I load the second AS2 swf the onLoadInit isn't triggered for the pngs. My guess is that the images are in a cache or something like that. I put a random string on the end of the request to try and avoid the cache but that doesn't seem to work.
The code in the as2 looks roughly like this:
var flagLoader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = Delegate.create(this, handleImageLoad);
flagLoader.addListener(listener);
var row:MovieClip = frame1["row" + (numLoaded + 1)];
flagLoader.loadClip(predictionData[numLoaded].flag + "?r="+Math.random(), row.flag);
I'm making sure to load only one image at a time (I've read anecdotal evidence loading more than one thing at a time can confuse the MovieClipLoader). For the first as2 file everything works great. When I load the second as2 file the handleImageLoad never gets called.
Update: Even more perplexing is if I reload the first AS2 movie (after the second AS2 movie fails to load the images) the first AS2 movie loads the images again fine.
Update 2: After trying to change from using a MovieClipLoader to polling (as was helpfully suggested) I have found some more evidence that is relevant.
When I load the first AS2 files and trace from the top level clip it prints out _root. The second AS2 file when loaded traces the same _root. This lead me to check if they were clashing on names and they are. Both have a child called frame. The first one, when I trace it comes out as _root.frame as expected. The second AS2 file traces _level0.instance3.instance118.instance111.frame. I'm guessing this is related to the problem.
Flash is keeping the _root of the two files the same but it is changing the locations of their children (for subsequently loaded files that have children with the same names). So either the onLoad is going to the wrong clip or the events about it loading are.