# Loading images into clips within for loop

**URL:** <https://forum.kirupa.com/t/loading-images-into-clips-within-for-loop/275675>\
**Category:** Uncategorized\
**Created:** [November 17, 2008, 3:50pm UTC](https://forum.kirupa.com/t/loading-images-into-clips-within-for-loop/275675 "2008-11-17T15:50:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![natronp](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@natronp](https://forum.kirupa.com/u/natronp)\
**Post date:** [November 17, 2008, 3:50pm UTC](https://forum.kirupa.com/t/loading-images-into-clips-within-for-loop/275675/1 "2008-11-17T15:50:45Z")

</div>

ok,

i’m trying to figure out how to replace loadMovie within a for loop where i’m populating dynamic movieclips.

I have:

```auto
/for (var i:uint = 0; i<finArray.length; i++)
	{
		var cubeFront:frontClip = new frontClip();
		var cubeBack:backClip = new backClip();
		
		var cF:MovieMaterial = new MovieMaterial(cubeFront, true, true, false);
		cF.interactive=true;
		
		var cB:MovieMaterial = new MovieMaterial(cubeBack, true, true, false);
		cB.interactive=true;
		
		//load image into clip
		var imageLoader = new Loader();
     
    		var theURL:String = finArray*;
     		var imageRequest = new URLRequest(theURL);

 		imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

     		imageLoader.load(imageRequest);

     		function onComplete(evt:Event) {
		trace("image"+ i +" loaded!");
          	cubeBack.holder.addChild(imageLoader.content);
		imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE);
		}
	  
	  
		
		var mList:MaterialsList = new MaterialsList({front:cF, back:cB, left:clearSide, right:clearSide,
							    top:clearSide, bottom: clearSide});
		var cube:Cube = new Cube(mList, 120, 1, 120, 1, 1, 1);
		scene.addChild(cube);
		//start cube in center
		cube.x=0;
		cube.y=0;
		cube.z=0;
		cube.alpha = 0;
		var cPosX:Number = XposArray*;
		var cPosY:Number = YposArray*;
		trace("cPosX: "+cPosX);
		trace("cPosY: "+cPosY);
		
		Tweener.addTween(cube,{x: cPosX, y: cPosY, alpha: 1.0, transition:"easeInOutQuad",time:1.5});
		
		cube.alpha = 1.0;
	}
	  

```

but it seems my URLRequest / Loader instances are being overwritten on each iteration of the loop (only the last image in the loop actually loads).

I thought maybe moving the declaration of the variables outside the loop as well as the onComplete function would work, but no go…
