# Unload external .swf

**URL:** https://forum.kirupa.com/t/unload-external-swf/326490
**Category:** flash
**Created:** [December 18, 2011, 1:46pm UTC](https://forum.kirupa.com/t/unload-external-swf/326490 "2011-12-18T13:46:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![macaudio](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@macaudio](https://forum.kirupa.com/u/macaudio)
#### Post date: [December 18, 2011, 1:46pm UTC](https://forum.kirupa.com/t/unload-external-swf/326490/1 "2011-12-18T13:46:02Z")

</div>

Hello there,

I am using a main .swf with buttons on a navigation menu that loads external .swf(s) - these load external videos (I use them as their backgrounds).

In the main .FLA I have used the following code (in the first and unique frame):

CODE

var Xpos:Number = 110; var Ypos:Number = 180; var swf:MovieClip; var loader:Loader = new Loader();  
var defaultSWF:URLRequest = new URLRequest(“swfs/eyesClosed.swf”);  
loader.load(defaultSWF); loader.x = Xpos; loader.y = Ypos; addChild(loader); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
// Btns Universal function function btnClick(event:MouseEvent):void {  
removeChild(loader); var newSWFRequest:URLRequest = new URLRequest(“swfs/” + event.target.name + “.swf”); loader.load(newSWFRequest); loader.x = Xpos; loader.y = Ypos; addChild(loader); } // Btn listeners  
inicio.addEventListener(MouseEvent.CLICK, btnClick); curriculum.addEventListener(MouseEvent.CLICK, btnClick); portfolio.addEventListener(MouseEvent.CLICK, btnClick); contacto.addEventListener(MouseEvent.CLICK, btnClick);      

I have added the following code in the only frame the external .swf(s) have:

CODE

import flash.events.Event;  
busto.addEventListener(Event.REMOVED\_FROM\_STAGE, onStageRemoved);  
function onStageRemoved(e:Event):void  
{  
// kill all listeneres and running processes here.  
}  

     

 I can make each button on the menu load each external .swf correctly with videos included - but when I leave that .swf using the navigation buttons to go to another section, the video and audio keep working in the background.

What am I doing wrong/have to change or add in the code?
