# Removing Movie Clips that have Loaders

**URL:** <https://forum.kirupa.com/t/removing-movie-clips-that-have-loaders/285950>\
**Category:** flash\
**Created:** [April 8, 2009, 4:48am UTC](https://forum.kirupa.com/t/removing-movie-clips-that-have-loaders/285950 "2009-04-08T04:48:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bong3](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@bong3](https://forum.kirupa.com/u/bong3)\
**Post date:** [April 8, 2009, 4:48am UTC](https://forum.kirupa.com/t/removing-movie-clips-that-have-loaders/285950/1 "2009-04-08T04:48:30Z")

</div>

Hello,  
I’m fairly new to Actionscript 3 (or any AS for that matter). I have 3 buttons layed out in my design (more to come ultimately). Once you click on any of these buttons, they will add their corresponding movie clips to the stage (button 1 will add movieclip 1 to the stage, etc). Each of these movie clips are details of a project (I’m building a portfolio). Some of these movie clips will have Loader classes in them, loading external images into them for a slideshow.

My problem comes in removing any previous movie clips from the stage when a new button is clicked (eg. click button 2 - movie clip 2 shows, click button 3 - remove movie clip 2 before adding movie clip 3 to the stage). I got it to work sorta, but the biggest problem comes with movie clips that have these Loader classes/images in them. When you click back to that project, you still see the last image loaded in that movie clip (like it was not cleared or reset when removed from the stage). How do I remove movie clips and all of their loaded children dynamically, while controlling them with buttons. Here is my sample code (the “showclip” function is where I need to fix my logic). Any help would be much appreciated.

//Add the Nav Buttons to the stage  
var btns\_mc:MC\_Btns = new MC\_Btns();  
btns\_mc.x = 0;  
btns\_mc.y = 45;  
addChild(btns\_mc);

//Instantiate each project detail movie clip

var project\_1:MC\_Project1 = new MC\_Project1();  
var project\_2:MC\_Project2 = new MC\_Project2();  
var project\_3:MC\_Project3 = new MC\_Project3();

//Load our buttons and project movie clips into arrays for easier access  
var buttonArray:Array = [btns\_mc.btn1\_mc, btns\_mc.btn2\_mc, btns\_mc.btn3\_mc];  
var loadProject:Array = [project\_1, project\_2, project\_3];

//Add the same event listener to all the buttons  
for(var i:int = 0 ; i \< buttonArray.length; i++)  
{  
buttonArray\*.addEventListener(MouseEvent.CLICK, showClip);  
}

//Make each button load its corresponding Project when clicked  
function showClip(evt:MouseEvent):void  
{  
for(var i:int = 0; i \< buttonArray.length; i++)  
{  
if(buttonArray\* == evt.currentTarget)  
{  
addChild(loadProject\*);  
loadProject\*.gotoAndPlay(2);  
}  
else  
{  
if(loadProject\*.stage != null)  
{  
removeChild(loadProject\*);  
}  
}  
}  
}
