-
1. Re: Why would this line not work?
Lee Burrows Mar 23, 2011 7:18 PM (in response to jlfitz)hi
firstly, i advise not putting functions inline. try this instead:
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void
{
DisplayObjectContainer(master_mc.getChildAt(i)).addChild(imgLoader);
}
this should fix your problem - if not, you'll need to post more of your project
-
2. Re: Why would this line not work?
jlfitz Mar 23, 2011 8:40 PM (in response to Lee Burrows)Thanks Lee. Your way is actually what I previously had been doing.
The issue is that I am accessing variables inside the init function that can't be accessed when the onComplete runs an outside function. I very well may be doing this incorrectly and would greatly value any help. Basically I can't figure out how to send an argument (like the var i for example) in the onComplete event function.
Here are the init and event functions:
function init(e:Event = null):void
{removeEventListener(Event.ADDED_TO_STAGE, init);
var boxSet:Object = new Object();
for (var i:int = 1; i < boxCount; i++)
{
boxSet[i] = new Sprite();
with (boxSet[i])
{
master_mc.graphics.beginFill(0xff1133);
master_mc.graphics.drawRect(nextXPos, 0, boxWidth, boxHeight+boxMargin);
master_mc.y = 130;
master_mc.addChild(boxSet[i]);
x = nextXPos;
imgLoader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addThumbnail);
imgLoader.load(new URLRequest("images/test_img0" + i + ".png"));
this.addEventListener(MouseEvent.CLICK, doButton);
}
nextXPos = i*(boxWidth+boxMargin);
} // END for loop...
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
{
DisplayObjectContainer(master_mc.getChildAt(7)).addChild(imgLoader);
removeEventListener(Event.COMPLETE, addThumbnail);
} -
3. Re: Why would this line not work?
Rothrock Mar 23, 2011 11:24 PM (in response to jlfitz)There is no reason you can't add the loader child to the display list when it is created. You don't have to wait for the complete event to do that.
-
4. Re: Why would this line not work?
jlfitz Mar 24, 2011 7:50 AM (in response to Rothrock)I didn't know that. So what is the purpose in using an image load onComplete? I seem to see it often. I guess I could use an onError event to make sure everything was captured if something did not load.
-
5. Re: Why would this line not work?
jlfitz Mar 24, 2011 8:19 AM (in response to jlfitz)Also, what is the reason for the error 1178: Attempted access of inaccessible property above? While I can do something different, that looked like a public/private package var issue. I'm not writing any classes but only code in the flash file. Please help me understand. Thanks...
-
6. Re: Why would this line not work?
Lee Burrows Mar 24, 2011 8:27 AM (in response to jlfitz)in your code you reference master_mc:
with (boxSet[i])
{
master_mc.graphics.beginFill(0xff1133);but boxSet[i].master_mc does not exist
re error 1178, what is on line 83 where the error occured?
-
7. Re: Why would this line not work?
Rothrock Mar 24, 2011 8:38 AM (in response to jlfitz)The purpose of the Complete event is to know when loading is complete.
Maybe you want to fade in the loaded asset. Well you need to know when that is complete so that you can start the fade. In that case you could attach the loader and make it invisible until it was done.
Or maybe you need to size the image after loading. You won't be able to know the size until it is loaded so you have to wait.
Maybe you are showing some kind of loading animation or such and you will need to know when to stop it.
There are a million other reasons to want to know when loading is done.

