# The supplied DisplayObject must be a child of the caller

**URL:** <https://forum.kirupa.com/t/the-supplied-displayobject-must-be-a-child-of-the-caller/321222>\
**Category:** Uncategorized\
**Created:** [April 13, 2011, 5:09pm UTC](https://forum.kirupa.com/t/the-supplied-displayobject-must-be-a-child-of-the-caller/321222 "2011-04-13T17:09:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheAwesomeDude](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@TheAwesomeDude](https://forum.kirupa.com/u/TheAwesomeDude)\
**Post date:** [April 13, 2011, 5:09pm UTC](https://forum.kirupa.com/t/the-supplied-displayobject-must-be-a-child-of-the-caller/321222/1 "2011-04-13T17:09:36Z")

</div>

What does it mean? And why doesnt my code work?

```php
stop();
import flash.events.Event;
var TimerApple:Timer = new Timer(500);

TimerApple.addEventListener(TimerEvent.TIMER, OnStartApple);

TimerApple.start();

function OnStartApple(e:Event){
 
    var af:Sprite = new Enemy();
    af.x= Math.random()*640;
    addChild(af);
    
     //Remove from stage, will give point
    af.addEventListener(Event.ENTER_FRAME, hitTheGround)
    function hitTheGround (e:Event):void
        {
            if(af.hitTestObject(Basket)){
            removeChild(af);
            }
        }

        //Controlling basket
        Basket.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);

        function fl_ClickToDrag_2(event:MouseEvent):void
        {
        Basket.startDrag();
        }

        }

```

And then the class “Enemy”

```php
package {
    import flash.events.Event;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.text.TextField; 
    public class Apple extends Sprite {
        private var core:Object;
        public function Apple() {
            addEventListener(Event.ADDED_TO_STAGE,onadd);
        }
        
        private function onadd(e:Event) {
            core=MovieClip(root);
            addEventListener(Event.ENTER_FRAME,loop);
        }
        
        private function loop(e:Event) {
            y+=10;
            }

        public function removeListeners():void {
            removeEventListener(Event.ENTER_FRAME, loop);
        }
    }
}

```
