I only discovered this problem when I started tracing values within and without different functions. In the onLoadInit function within my for loop, it only ever receives the last iteration of the loop:
imgArray = new Array("image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg")
var thumbLoader:MovieClipLoader = new MovieClipLoader();
var thumbLoadListener:Object = new Object();
thumbLoader.addListener(thumbLoadListener);
for (var i:Number = 0; i < imgArray.length; i++) {
gallery.attachMovie("showcase", "img" + i, i);
var clip:MovieClip = gallery["img" + i];
var thumb:MovieClip = clip.showcaseThumb_mc;
**trace(i); ** // Traces 0,1,2,3
thumbLoadListener.onLoadInit = function() {
**trace(i + ": " + clip);** // Traces 3,3,3,3
}
thumbLoader.loadClip("thumbs/" + imgArray*, thumb);
}
Assuming that imgArray’s length is 4, then the first trace statement will give me 0,1,2,3. However, the trace inside the loadClips’s onLoadInit function will just spit out the last iteration for the number of loops, i.e. 3, 3, 3, 3.
I really wanted to be able to use loadClip specifically for the onLoadInit function so I could size and place all my thumbnails dynamically, but I can’t seem to find a way around this problem. Any suggestions?