bjurtown
bjurtown

Reputation: 173

Unloading an swf upon exiting frame

I've had a search around and couldn't apply anything i found to my code to get it to work.

I'm building a site where navigating to each page (frame) will load an external swf with the content. ideally i would like for the content to unload when i navigate away from the frame, so that i can then load a new swf.
here's my as3 for loading the swf:

var swfLoader:Loader = new Loader();

stage.addChild(swfLoader); swfLoader.x = 0; swfLoader.y = 100;

var bgURL:URLRequest = new URLRequest("gallery_swf/reg_slide.swf");

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);

swfLoader.load(bgURL);

function loadProdComplete(e:Event):void {

trace("file loaded");

}

Upvotes: 0

Views: 1054

Answers (2)

Dave Hart
Dave Hart

Reputation: 347

The safest method to unload an external swf is to use the unloadAndStop method of your loader. If you are targeting Flash Player 9 tho, you will not be able to use this method and will have to use unload() instead. Please note that unload() requires additional manual work to ensure everything is properly unloaded.

To quote the link :

Though Loader.unload removes the child of the Loader object, the unloaded object will still run in the background until it is actually disposed of by the garbage collector. Since the garbage collector does not dispose of objects that are referred to, the "unloaded" content could perhaps never be removed (for example, event listeners could reference the object).

Upvotes: 0

Gurpreet Singh
Gurpreet Singh

Reputation: 21233

Simply use:

swfLoader.unload(); 

to unload the swf.

Upvotes: 0

Related Questions