Hi, I am trying to load up a series of images and attach them to the newly created boxes in this loop. But I cant figure out how to keep everything inside the loop where the var scope is valid. When the image loads it fires the onLoadComplete and takes teh addChild part outside the loop, in turn restricting the vars from being access right. I am open to any ideas or examples of how better to do this.
If you are an expert please help I must be done asap and feel completely stuck. Many thanks. Here is the code:
function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var boxSet:Object = new Object();
master_mc = new MovieClip();
addChild(master_mc);
master_mc.y = 110;
for (var i:int = 1; i < boxCount; i++)
{
boxSet["box"+i] = new Sprite();
with (boxSet["box"+i])
{
name = "box" + i;
master_mc.graphics.beginFill(0xff1133);
master_mc.graphics.drawRect(nextXPos, 0, boxWidth, boxHeight+boxMargin);
x = nextXPos;
imgLoader = new Loader();
//imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addThumbnail);
imgLoader.load(new URLRequest("http://www.yazizle.com/files/test_img0" + i + ".png"));
addEventListener(MouseEvent.CLICK, doButton);
}
nextXPos = i*(boxWidth+boxMargin);
}
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
master_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
master_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
}
function addThumbnail(event:Event):void
{
addChild(imgLoader);
removeEventListener(Event.COMPLETE, addThumbnail);
}