Hi Sander.
When you add an EventListener you should in 99% set the weak reference
flag like this:
mLoader.contentLoaderInfo.addEventListener( Event.COMPLETE,
pageComplete,false,0,true );
The last parameter - here set to true - makes the reference to your
pageComplete function
weak. Meaning if this reference is the only reference left to your removed
object that object
becomes ready for garbage collection. Have a look in the as3 language reference
to learn more about it.
Mark
Sander Schuurman schrieb:
Hi cool list!
I'm trying do build a generic structure of pages (swf's) loaded in a main swf,
and unloading as well ofcourse.
Now I'm trying to unload a loaded swf, with the famous Garbage Collection. But
I'm not sure I'm doing it the right way. Hope you could point me in the right
direction.
My code:
private function loadPage( qUrl :String ) :void
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest( qUrl );
mLoader.contentLoaderInfo.addEventListener( Event.COMPLETE,
pageComplete );
mLoader.load( mRequest );
}
private function pageComplete( e :Event ) :void
{
currentPage = e.currentTarget.content;
currentPage.addEventListener( Page.PAGE_INIT, initPage );
currentPage.addEventListener( Page.GOTO_PAGE, gotoPage );
addChild(currentPage);
}
private function gotoPage( e :Event ) :void
{
var nextPage = currentPage.gotoPage;
currentPage.removeEventListener( Page.PAGE_INIT, initPage );
currentPage.removeEventListener( Page.GOTO_PAGE, gotoPage );
var loader:Loader = Loader( e.target );
loader.unload();
loadPage( nextPage );
}
I'm not sure about the gotoPage method, if I can make a Loader object of the
currentPage and unload it. Is it totally ready for the GC to be deleted?
Thnx in advance.
Sander
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders