View Full Version : Loader Content Null after Event.COMPLETE fires
titanag
March 25th, 2010, 01:44 PM
I have an array of loaders loading .jpgs. After the Event.COMPLETE fires, I trace the content at the current page and it tells me the content is null, BUT on testing the images appear just fine. Here's my code:
for (var i:uint = 0; i<pages.length; i++){
pages[i].contentLoaderInfo.addEventListener( Event.COMPLETE, loadImg, false, 0, true );
pages[i].load( new URLRequest("brochure-kids-images/kids" + getWhichImage(i) + "sm.jpg"));
trace("content " + pages[i].content); //returns null
//....code goes on
IQAndreas
March 25th, 2010, 03:24 PM
That is a VERY common misconception.
When you run the ".load()" function, Flash does not stop and wait for the loading to complete. It keeps going while in the background everything is loading. That means, the content is still loading while you are running the code after "load()". And since it's not done loading, content will be null.
If you check for the content inside of "loadImg", you should be able to get a result.
Do you understand? I will gladly try to explain better.
titanag
March 25th, 2010, 04:49 PM
Doesn't the Event.COMPLETE stop everything until the .load() function finishes? Isn't that the whole point of Event.COMPLETE?
Maqrkk
March 25th, 2010, 04:58 PM
No. Everything keeps going. All that the Event does, is listen for the COMPLETE event, then execute the specified listener function:
pages[i].contentLoaderInfo.addEventListener( Event.COMPLETE, loadImg, false, 0, true );
function loadImg(e:Event):void
{
// This is the listener function, gets executed when it is done loading.
}
titanag
March 25th, 2010, 04:59 PM
aha. thanks for the explanation!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.