# Removing a Child from within itself

**URL:** <https://forum.kirupa.com/t/removing-a-child-from-within-itself/271317>\
**Category:** Uncategorized\
**Created:** [September 21, 2008, 2:57pm UTC](https://forum.kirupa.com/t/removing-a-child-from-within-itself/271317 "2008-09-21T14:57:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrRobot](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/drrobot/32/3907_2.png) [@DrRobot](https://forum.kirupa.com/u/DrRobot)\
**Post date:** [September 21, 2008, 2:57pm UTC](https://forum.kirupa.com/t/removing-a-child-from-within-itself/271317/1 "2008-09-21T14:57:39Z")

</div>

Alright, so i am doing soem work in flashdevelop and im encountering a small problem when i try to remove a movieclip from within itself.

MainChar class

```php

package  
{
 import flash.display.MovieClip;
 import flash.events.Event;
 import flash.events.KeyboardEvent;

 public class MainChar extends Body
 {
  
  public function MainChar()
  {  
   this.addEventListener(Event.ADDED_TO_STAGE, staging);
  }
  
  private function staging(e:Event):void 
  {
   stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
  }
  
  private function handleKeyDown(e:KeyboardEvent):void 
  {
   switch(e.keyCode) 
   {
    case 90 :
     addChild(new Anim(this));
     break;
   }
  }

 }
 
}

```

```php

package  
{
 import flash.display.MovieClip;
 import flash.display.Sprite;
 
 /**
  * ...
  * @author DefaultUser (Tools -> Custom Arguments...)
  */
 public class Body extends MovieClip
 {
  public var Name:String;
  public var body:Sprite = new Sprite();
  
  public function Body() 
  {
   body.graphics.beginFill(Math.random()*0xffffff);
   body.graphics.drawCircle(0, 0, 10);
   body.graphics.endFill();
   addChild(body);
  }  
 }
 
}

```

this is what gets added from the MainChar class:

```php

package  
{
 import flash.display.MovieClip;
 import flash.events.Event;
 
 /**
  * ...
  * @author DefaultUser (Tools -> Custom Arguments...)
  */
 [Embed (source = "library.swf", symbol = "Swing")]
 public class Anim extends MovieClip
 {
  
  private var remover:MovieClip;
  public function Anim(cest:MovieClip) 
  {
   remover = cest;
   addEventListener(Event.ENTER_FRAME, init);
  }
  
  private function init(e:Event):void 
  {
   if (currentFrame == totalFrames)
   {
    remover.removeChild(this);
   }
  }
  
 }
 
}

```

its throwing that null object reference error…:

```auto
TypeError: Error #1009: Cannot access a property or method of a null object reference.

```
