# Issues unloading swf

**URL:** <https://forum.kirupa.com/t/issues-unloading-swf/285675>\
**Category:** flash\
**Created:** [April 3, 2009, 7:26pm UTC](https://forum.kirupa.com/t/issues-unloading-swf/285675 "2009-04-03T19:26:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![soundmatic](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@soundmatic](https://forum.kirupa.com/u/soundmatic)\
**Post date:** [April 3, 2009, 7:26pm UTC](https://forum.kirupa.com/t/issues-unloading-swf/285675/1 "2009-04-03T19:26:08Z")

</div>

I have 5 buttons that loads 5 external swf’s which contain a video, graphics etc. When try to unload i still hear the video playing looks like I am not able to unload the swf. Following is the code. Probably it is a bit messy but i am trying trial and error in the attempts to make sense of loading swfs in AS3. Please suggest.

var loader:Loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

var project1:URLRequest = new URLRequest(“projects/p1.swf”);  
var project2:URLRequest = new URLRequest(“projects/p2.swf”);  
var project3:URLRequest = new URLRequest(“projects/p3.swf”);  
var project4:URLRequest = new URLRequest(“projects/p4.swf”);  
var project5:URLRequest = new URLRequest(“projects/p5.swf”);

p1.addEventListener (‘mouseDown’, function() {  
loader.load(project1);  
});

p2.addEventListener (‘mouseDown’, function() {  
loader.load(project2);  
});

p3.addEventListener (‘mouseDown’, function() {  
loader.load(project3);  
});

p4.addEventListener (‘mouseDown’, function() {  
loader.load(project4);  
});

p5.addEventListener (‘mouseDown’, function() {  
loader.load(project5);  
});

function loadComplete(event:Event):void {  
addChild(loader);  
MovieClip(loader.content).button.addEventListener(MouseEvent.CLICK, unloader);  
}

function unloader(event:MouseEvent):void {  
removeChild(loader);  
loader.unload();  
loader = null;  
}

p1.addEventListener(MouseEvent.CLICK, loadproject1);

function loadproject1(event:MouseEvent):void {  
if(loader == null) {  
loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);  
loader.load(project1);  
}  
}

p2.addEventListener(MouseEvent.CLICK, loadproject2);

function loadproject2(event:MouseEvent):void {  
if(loader == null) {  
loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);  
loader.load(project2);  
}  
}

p3.addEventListener(MouseEvent.CLICK, loadproject3);

function loadproject3(event:MouseEvent):void {  
if(loader == null) {  
loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);  
loader.load(project3);  
}  
}

p4.addEventListener(MouseEvent.CLICK, loadproject4);

function loadproject4(event:MouseEvent):void {  
if(loader == null) {  
loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);  
loader.load(project4);  
}  
}

p5.addEventListener(MouseEvent.CLICK, loadproject5);

function loadproject5(event:MouseEvent):void {  
if(loader == null) {  
loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);  
loader.load(project5);  
}  
}
