Search code examples
actionscript-3flashremovechilddisplayobject

AS3: The supplied DisplayObject must be a child of the caller


I can't figure this one out, i'm sorry - really an ActionScript noobie here. I've searched for the problem but the answers i keep finding don't solve my problems. Anyone know whats wrong?

public function KikkerOgen() 
        {
            addEventListener(MouseEvent.CLICK, isClicked);
            timer.addEventListener(TimerEvent.TIMER, Knipperen);
            timer.start();
            gotoAndStop(13);
        }

        function isClicked (event:MouseEvent):void 
        {
            removeChild(this);
        }

Solution

  • Sorry your problem is in:

    removeChild(this);
    

    You are trying to remove the object from the object itself!!!

    That's what you should do:

    this.parent.removeChild(this);