# Unloading a swf that adds itself after a given time

**URL:** <https://forum.kirupa.com/t/unloading-a-swf-that-adds-itself-after-a-given-time/320986>\
**Category:** Uncategorized\
**Created:** [April 7, 2011, 11:38am UTC](https://forum.kirupa.com/t/unloading-a-swf-that-adds-itself-after-a-given-time/320986 "2011-04-07T11:38:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ludob](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@ludob](https://forum.kirupa.com/u/ludob)\
**Post date:** [April 7, 2011, 11:38am UTC](https://forum.kirupa.com/t/unloading-a-swf-that-adds-itself-after-a-given-time/320986/1 "2011-04-07T11:38:59Z")

</div>

Hi everyone i am working on this code

[as]portfolio\_btn.addEventListener(MouseEvent.CLICK, portfolio);  
home\_btn.addEventListener(MouseEvent.CLICK, home);

var loader:Loader=new Loader();  
loader.load(new URLRequest(“portfolio.swf”));

function portfolio(E:Event):void  
{  
var t:Timer;

if(t==null){  
t= new Timer(2000,0);  
t.start();  
t.addEventListener(TimerEvent.TIMER,addSwf);

function addSwf(e:TimerEvent):void{

addChild(loader);

}  
}  
}

function home(E:Event):void  
{  
removeChild(loader);  
}  
[/as]

so i can click on a button and after 2 seconds my swf loads fine. but then when i click on the other button to unload, remove it. It plays again…  
how can i remove it so it doesnt keep adding itself.

Thanks for any help
