Common Flash/Flex AS3 Mistake... Loader Doesn't Work - No Events Working When Loading External URLs

If you seem to have everything set up correctly with a Loader class instance, but there's just nothing happening... You probably made the same mistake I've made a number of times when coding a little too quickly:  attaching the event listeners to the Loader object itself, rather than your loader's property: .contentLoaderInfo - where all the information and events on loading status actually occur.

For example...

 The Common Wrong Way:


var myLoader:Loader = new Loader();
myLoader.addEventListener(Event.COMPLETE, onLoadComplete);
myLoader.load( new URLRequest("externalExampleImage.jpg") );

...and then you wonder why the event never fires, there is no error, and you know your image is there... doht!

The Right Way:


var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
myLoader.load( new URLRequest("externalExampleImage.jpg") );

... works every time!

Adobe Documentation Reference:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html

3 comments (Add your own)

1. ula wrote:
This saved me! Thank you!

November 27, 2009 @ 9:06 PM

2. thorsten wrote:
THANKS!

April 20, 2010 @ 6:39 AM

3. sean wrote:
glad i could help :)

April 20, 2010 @ 1:41 PM

Add a New Comment

Enter the code you see below:
code
 

Comment Guidelines: No HTML is allowed. Off-topic or inappropriate comments will be edited or deleted. Thanks.