# removeChild Help!

**URL:** <https://forum.kirupa.com/t/removechild-help/285232>\
**Category:** flash\
**Created:** [March 29, 2009, 3:36am UTC](https://forum.kirupa.com/t/removechild-help/285232 "2009-03-29T03:36:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vxd](https://avatars.discourse-cdn.com/v4/letter/v/848f3c/32.png) [@vxd](https://forum.kirupa.com/u/vxd)\
**Post date:** [March 29, 2009, 3:36am UTC](https://forum.kirupa.com/t/removechild-help/285232/1 "2009-03-29T03:36:45Z")

</div>

Hi All!,

I’m have a problem removing a child from the stage.  
It will close the last MC it added to the stage but it won’t close the MC I add before the last MC.  
I know it’s because when I add in the new Sprite it will be referenced and no the old one.

Here is the code so you can understand what I’m trying to do

```auto

button.addEventListener(MouseEvent.CLICK, buttonClick)

function buttonClick(evt:Event):void {
var window:MovieClip = new Window()//window is a MovieClip from the library. 
addChild(window)
closeButton.addEventListener(MouseEvent.CLICK, closeWindow) //closeButton is on the window

}

function closeWindow(evt:Event):void {
closeButton.removeChild(window)
}

```

here is the error

```auto
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/removeChild()
    at IconArray04/::closeWindow()

```

Thanks  
vxd
