# Problems removing SWF when loaded

**URL:** <https://forum.kirupa.com/t/problems-removing-swf-when-loaded/320654>\
**Category:** Uncategorized\
**Created:** [March 29, 2011, 2:34pm UTC](https://forum.kirupa.com/t/problems-removing-swf-when-loaded/320654 "2011-03-29T14:34:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisW182](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@ChrisW182](https://forum.kirupa.com/u/ChrisW182)\
**Post date:** [March 29, 2011, 2:34pm UTC](https://forum.kirupa.com/t/problems-removing-swf-when-loaded/320654/1 "2011-03-29T14:34:53Z")

</div>

I am trying to load an external .SWF into my current .SWF. I have managed to get it loading onto my application, but then once the animation has finished and i click onto another button, i.e. ‘gallery’ or ‘contact’ i want the swf to be removed, i know i need to add a remove child somewhere but i dont know how. can anyone help. this is my code.

import fl.controls.ProgressBar;  
import flash.events.Event;  
/\*  
You must keep the variables and functions you can write  
additional ones but you must not start from scratch.  
on scene home - delete the layer with named animation and create the animation this size  
\*/

galleryBT.addEventListener(MouseEvent.CLICK, galleryDisplay);  
// used to navigate to the gallery page  
function galleryDisplay(event:Event):void{  
gotoAndStop(“gallery”);  
}  
homeBT.addEventListener(MouseEvent.CLICK, homeDisplay);  
// used to navigate to the gallery page  
function homeDisplay(event:Event):void{  
gotoAndStop(“home”);  
}  
contactBT.addEventListener(MouseEvent.CLICK, contactDisplay);  
// used to navigate to the gallery page  
function contactDisplay(event:Event):void{  
gotoAndStop(“contact”);  
}  
//loading the animation  
var swfRequest:URLRequest = new URLRequest(“assignmentfinal.swf”);  
var swfLoader:Loader = new Loader();  
var my\_pb:ProgressBar = new ProgressBar();  
var swfOnStage:Boolean=false;

my\_pb.source = swfLoader.contentLoaderInfo;  
my\_pb.x = 200;  
my\_pb.y = 600;

function loadFile():void{  
addChild(my\_pb);  
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded, false, 0, true);  
swfLoader.load(swfRequest);  
swfOnStage=true;  
}  
loadFile();  
function swfLoaded(event:Event):void{  
swfLoader.x=40;  
swfLoader.y=155;  
addChild(swfLoader);  
removeChild(my\_pb);  
swfOnStage=false;  
}

stop();
