# Action script 3 question: addChild and removeChild on same button?

**URL:** <https://forum.kirupa.com/t/action-script-3-question-addchild-and-removechild-on-same-button/325405>\
**Category:** Uncategorized\
**Created:** [October 13, 2011, 2:44pm UTC](https://forum.kirupa.com/t/action-script-3-question-addchild-and-removechild-on-same-button/325405 "2011-10-13T14:44:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincentccw](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@vincentccw](https://forum.kirupa.com/u/vincentccw)\
**Post date:** [October 13, 2011, 2:44pm UTC](https://forum.kirupa.com/t/action-script-3-question-addchild-and-removechild-on-same-button/325405/1 "2011-10-13T14:44:06Z")

</div>

I’m trying to make a button that when u click once, the movieclip will be removed and second time back on stage and so forth…

# somehow i get this error

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.  
at flash.display:DisplayObjectContainer/removeChild()  
at sample\_fla::MainTimeline/btnClick()

==================================

Anyone can help me with this, since I’m doing an interactive web for client and the deadline is near… thanks in advance.

these are my code:

///////////////////////////////////////////////////

stop();

var swf:MovieClip;  
var loader:Loader= new Loader();  
var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");  
//default swf when loaded

loader.load(defaultswf);

//add to stage  
allSwfLoadHere.addChild(loader);  
var boolean:Boolean = true ;

function btnClick(event:MouseEvent):void {

if(boolean == true){  
allSwfLoadHere.removeChild(loader);  
boolean == false  
}

if(boolean ==false){  
allSwfLoadHere.addChild(loader);  
boolean == true  
}  
}

newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

//////////////////////////////////////////////////////
