# MovieClipLoader/loadClip within 'for' loop

**URL:** <https://forum.kirupa.com/t/moviecliploader-loadclip-within-for-loop/282703>\
**Category:** flash\
**Created:** [February 25, 2009, 12:47pm UTC](https://forum.kirupa.com/t/moviecliploader-loadclip-within-for-loop/282703 "2009-02-25T12:47:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnymeerkat](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnnymeerkat/32/1254_2.png) [@johnnymeerkat](https://forum.kirupa.com/u/johnnymeerkat)\
**Post date:** [February 25, 2009, 12:47pm UTC](https://forum.kirupa.com/t/moviecliploader-loadclip-within-for-loop/282703/1 "2009-02-25T12:47:49Z")

</div>

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:

```auto

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?
