# Simple question open/close button

**URL:** <https://forum.kirupa.com/t/simple-question-open-close-button/318576>\
**Category:** Uncategorized\
**Created:** [January 24, 2011, 3:39pm UTC](https://forum.kirupa.com/t/simple-question-open-close-button/318576 "2011-01-24T15:39:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drakkonblade](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@drakkonblade](https://forum.kirupa.com/u/drakkonblade)\
**Post date:** [January 24, 2011, 3:39pm UTC](https://forum.kirupa.com/t/simple-question-open-close-button/318576/1 "2011-01-24T15:39:44Z")

</div>

getting an error;  
**“ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.  
at flash.display: ![](http://forum.kirupa.com/uploads/kirupa/1495/f1fea26928e562b8.gif)isplayObjectContainer/removeChild()  
at Untitled\_fla::MainTimeline/RedClick()”**

what i successfully did was having a button open and close a movie clip and if you changed frame that it close by default.

> helpButton.addEventListener(MouseEvent.CLICK, clickHandler);

var isThere:Boolean = false;  
var mcHandle:MovieClip = new dahelpbox();

//position the textbox eli  
mcHandle.x = 80;  
mcHandle.y = 750;

function clickHandler(e:MouseEvent):void {  
if (!isThere) {  
addChild(mcHandle);  
isThere = !isThere;  
} else {  
removeChild(mcHandle);  
isThere = !isThere;  
}  
}

newButton.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {  
if (isThere) {  
removeChild(mcHandle);  
isThere = !isThere;  
gotoAndStop(10);  
} else {  
gotoAndStop(10);  
}  
}

\*\*\*\* Issue occurs when i try to have button A open/close movieclip A; as button B open/close movieclip B  
new code i wrote…

> green\_btn.addEventListener(MouseEvent.CLICK, GreenClick);  
> red\_btn.addEventListener(MouseEvent.CLICK, RedClick);  
> help\_btn.addEventListener(MouseEvent.CLICK, ClickHandler);  
> text\_btn.addEventListener(MouseEvent.CLICK, ClickHandler2);

var isThere:Boolean = false;  
var isDhere:Boolean = false;  
var mcHandle:MovieClip = new popbox();  
var mcHandler:MovieClip = new popper();

mcHandle.x = 500;  
mcHandle.y = 250;  
mcHandler.x = 200;  
mcHandler.y = 500;

function ClickHandler(event:MouseEvent):void {  
if (!isThere) {  
addChild(mcHandle);  
isThere = !isThere;  
} else {  
removeChild(mcHandle);  
isThere = !isThere;  
}  
}

function ClickHandler2(event:MouseEvent):void {  
if (!isDhere) {  
addChild(mcHandler);  
isDhere = !isDhere;  
} else {  
removeChild(mcHandler);  
isDhere = !isDhere;  
}  
}

function GreenClick(event:MouseEvent):void  
{  
if (isThere||isDhere) {  
removeChild(mcHandle);  
removeChild(mcHandler);  
isThere = !isThere;  
isDhere = !isDhere;  
gotoAndStop(1);  
} else {  
gotoAndStop(1);  
}  
}

function RedClick(event:MouseEvent):void  
{  
if (isThere||isDhere) {  
removeChild(mcHandle);  
removeChild(mcHandler);  
isThere = !isThere;  
isDhere = !isDhere;  
gotoAndStop(2);  
} else {  
gotoAndStop(2);  
}  
}
