views:

202

answers:

1

Recently in a project I configured a custom Loader class as follows First I define my Loader as a private variabel

private var _myLdr:Loader

//Then in the constructor

_myLdr = new Loader();   
_myLdr.contentLoaderInfo.addEventListener( Event.COMPLETE, doneImgLoad );
_myLdr.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, loadProgress );
_myLdr.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, ioError );

And then finally when I need to load a new asset I call my Loader instance via a public method

_myLdr.load(new URLRequest ('myswftoLoad.swf') );

So far so good....UNLESS you happen to view your page using the debug version of FlashPlayer 9.024 in which case you get

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::Loader/_load()

WTF???!!

So to correct I need to instantiate a new loader EVERY time I load a new asset.

Can someone tell me which method would be considered a 'best practice'?

A: 

A Loader instance can have utmost one child at a time. Call _myLdr.unload(); before issuing subsequent load() requests with same Loader instance.

That being said, I would rather create a new Loader instance for each loads (and make sure that previous instances are properly unloaded when they are no longer needed).

Amarghosh
Tried that and I still get 'ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::Loader/unload()'....although strange that I ONLY get the error with the 9.024 version of the debug player and not version 10 of the debug player. The other reason creating a new Loader instance each time you load an external asset seems counter-intuitive is that I assume each new Loader instance adds a small amount to the memory used by the application. In my case the application is used in a kiosk setting and I'm trying to avoid any memory leaks....
eco_bach
Am going to assume that 'best practice' would be to create new Loader instance(with associated listeners' each time. But also to have a 'cleanup' method that removes the loader from the display list as well as its listeners.
eco_bach
Are you adding `loader.content` to some other parent? By default it will be the child of the corresponding `Loader` object that loaded it - and I guess unload method might be calling `loader.remove(loader.content)` and will fail if you are adding loader.content to something else.
Amarghosh