# Problem with removeChild

**URL:** <https://forum.kirupa.com/t/problem-with-removechild/305332>\
**Category:** flash\
**Created:** [February 23, 2010, 5:56pm UTC](https://forum.kirupa.com/t/problem-with-removechild/305332 "2010-02-23T17:56:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rubenos](https://avatars.discourse-cdn.com/v4/letter/r/f08c70/32.png) [@Rubenos](https://forum.kirupa.com/u/Rubenos)\
**Post date:** [February 23, 2010, 5:56pm UTC](https://forum.kirupa.com/t/problem-with-removechild/305332/1 "2010-02-23T17:56:22Z")

</div>

Hi,

First post here, read some stuff and tips but I’d like your help!

```auto
package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    
    public class Main extends Sprite {
        public var myKnop1:Knop1;
        public var myKnop2:Knop2;
        public var myKnop3:Knop3;
        public var myKnop4:Knop4;
        public var myCat:Cat;
        public function Main() {
            myKnop1 = new Knop1();
            myKnop1.x = 0;
            myKnop1.y = 0;
            addChild(myKnop1);
            addEventListener(MouseEvent.MOUSE_UP, opKnop2);
        }
        public function opKnop2(e:Event):void {
            removeChild(myKnop1);
            myKnop2 = new Knop2();
            myKnop2.x = 0;
            myKnop2.y = 0;
            addChild(myKnop2);
            addEventListener(MouseEvent.MOUSE_UP, opKnop3);
        }
        public function opKnop3(e:Event):void {
            removeChild(myKnop2);
            myKnop3 = new Knop3();
            myKnop3.x = 0;
            myKnop3.y = 0;
            addChild(myKnop3);
            addEventListener(MouseEvent.MOUSE_UP, opKnop4);
        }
        public function opKnop4(e:Event):void {
            removeEventListener(MouseEvent.MOUSE_UP, opKnop3);
            removeChild(myKnop3);
            myKnop4 = new Knop4();
            myKnop4.x = 0;
            myKnop4.y = 0;
            addChild(myKnop4);
        }
    }
}

```

If I compile this, I just keep getting

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

```

But if I’m right, it’s in the right section?

I searched alot on this forum and google, but the cases where all different then mine.

With kind regards,  
Rubenos
