Accessibility

TechNote

Flash Player 10, Action Script 3: Loader.unloadAndStop

History

The Loader.unloadAndStop feature was added to Action Script 3's API to automate a process that was previously manual when using Loader.unload.

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).

Example: A SWF file that has a music track is loaded into an application. Later, the SWF is unloaded using Loader.unload(). Though the SWF will be removed from the screen, the music will still be heard.

SOLUTION

Loader.unloadAndStop is a new addition to Action Script 3's API. It helps developers to correctly stop and unload loaded content using the Loader.load/loadBytes APIs.

Loader.unloadAndStop is very similar to Loader.unload. However, it adds one more step. After the "unload" event is dispatched to the LoaderInfo class, Flash Player recursively attempts to stop and clear as many objects as possible (Sounds, NetStreams, EventListeners, etc.) within the loaded SWF. This feature is especially useful when unloading unknown 3rd party content.

Example

 import flash.display.Loader
		
import flash.net.URLRequest
import flash.events.Event

var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event){
addChild(myLoader);
});

myLoader.load(new URLRequest("item2.swf"));
btnUnload.addEventListener(MouseEvent.CLICK,function(){
// Calling this method will unload and recursively stop the content of the movie.
myLoader.unloadAndStop();
});

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support

Document Details

ID:kb403670

Products Affected:

flash
flashplayer