Error #2025: The supplied DisplayObject must be a child of the caller

For a great deal of time now, i’ve been trying to solve what seems like something so easy to fix. However, after a great deal of time trying different methods with no success, I had no option but to ask for help.

Here is the problem: I’m trying to remove something from the stage when it hits an object. Sounds easy right? I thought so to as i’ve never had this amount of trouble before when using ‘removeChild’

Anyway… to the code…

package  {	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.display.DisplayObject;
	import flash.display.Stage;
	
	
	public class EnemyBullet extends MovieClip {
		
		public var FIRE_SPEED:int = 10;


		public function EnemyBullet() {
			this.addEventListener(Event.ENTER_FRAME, moveBulletDown)
			this.addEventListener(Event.ADDED_TO_STAGE, addEvents)
		}
		
		public function addEvents(event:Event)
		{
			addEventListener(Event.ENTER_FRAME, checkCollision)
		}
		
		public function moveBulletDown(event:Event)
		{
			this.y += FIRE_SPEED;
		}
		
		public function checkCollision(event:Event)
		{
			if(stage.contains(this))
			{
				if(hitTestObject(Player.tar))
					{
						this.removeChild(this);
						Player.playerHealth - 10;
						trace(Player.tar)
						trace(this);
					}
			}


		}

You can see where the hitTestObject takes place and where i try to remove it. Yet, when it hits i get the…Error #2025: The supplied DisplayObject must be a child of the caller.

I have tried using ‘parent.removeChild’ which it does remove it from the stage, but it then errors saying ‘parent is null’ i’ve also tried the following:

  • this.parent.removeChild
  • parent.this.removeChild
  • stage.removeChild
  • the if(contains(this))
  • tried using ADDED_TO_STAGE

and various other ways to try and solve this problem. If someone could help me to fix this problem, it would help me out a great deal. Also, Player.tar is just saying that the target for it to hit is the player.

If someone could also tell me what ‘parent’ actually does and what ‘this’ actually does and when it can/can’t be used?

Thanks