Tag Archives: REMOVED_FROM_STAGE

Unload an externally loaded swf file

Unload an externally loaded swf file

How to remove or unload an externally loaded swf file from your project?

It happenes a lot that you try to load an external SWF file into your project. maybe in your portfolio or some swf movies or sound files. The problem I am going to talk about here is about the common problem of unloading the swf files!

you see, if you have loaded an swf file which has some music on it playing constantly, when you try to unload/remove that swf, the sound keeps playing! (not just sounds, maybe some Event.ENTER_FRAME or other listeners are still working)

to avoid this problem, the best solution I can think of is to add a REMOVED_FROM_STAGE listener in your external swf file so it can listen to when it’s removed from the stage so it can kill the running processes inside itself.

simply add it like this:

[cc lang="php" line_numbers="true" nowrap="false" width="100%"]
import flash.events.Event;
this.addEventListener(Event.REMOVED_FROM_STAGE, onStageRemoved);
function onStageRemoved(e:Event):void
{
// kill all listeneres and running processes here.
}
[/cc]

4 Comments
Contact UsContact Us
Contact MyFlashLab Team?

Feel free to drop us an email if you have any question regarding the TextArea class or the tag modules.

* required
Send Message