# Sprite trying to remove itself from the stage is throwing errors

**URL:** https://forum.kirupa.com/t/sprite-trying-to-remove-itself-from-the-stage-is-throwing-errors/293894
**Category:** Uncategorized
**Created:** [August 5, 2009, 3:00pm UTC](https://forum.kirupa.com/t/sprite-trying-to-remove-itself-from-the-stage-is-throwing-errors/293894 "2009-08-05T15:00:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![zachwlewis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/zachwlewis/32/350_2.png) [@zachwlewis](https://forum.kirupa.com/u/zachwlewis)
#### Post date: [August 5, 2009, 3:00pm UTC](https://forum.kirupa.com/t/sprite-trying-to-remove-itself-from-the-stage-is-throwing-errors/293894/1 "2009-08-05T15:00:20Z")

</div>

I’m trying to have a bullet Sprite remove itself from the stage once it is off the stage, but Flash keeps throwing #1009 errors at me. I’ve looked over the code several times and don’t understand what’s wrong.

Bullet code:

```auto
package {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.*;
	
	public class Bullet extends Sprite {
		private var bullet_direction;
		private var bullet_speed;
		public function Bullet(xLoc:Number, yLoc:Number, angle:Number, speed:Number) {
			x = xLoc;
			y = yLoc;
			bullet_direction = angle;
			bullet_speed = speed;
			addEventListener(Event.ENTER_FRAME, BulletMovement,false,0,true);
		}

		public function BulletMovement(e:Event) {
			y -= bullet_speed * Math.sin(bullet_direction);
			x += bullet_speed * Math.cos(bullet_direction);
			if ( x > 500 || x < -20 || y > 660 || y < -20 ) {
				DestroyBullet();
			}				
		}

		public function DestroyBullet():void {
			removeEventListener(Event.ENTER_FRAME, BulletMovement);
			(stage as MovieClip).removeChild(this);
		}
	}
}

```

Error message:

```auto
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Bullet/DestroyBullet()
	at Bullet/BulletMovement()

```

Any help would be much appreciated.
