# Checking if child exists

**URL:** <https://forum.kirupa.com/t/checking-if-child-exists/324965>\
**Category:** flash\
**Created:** [September 18, 2011, 10:50am UTC](https://forum.kirupa.com/t/checking-if-child-exists/324965 "2011-09-18T10:50:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ematrix](https://avatars.discourse-cdn.com/v4/letter/e/bcef8e/32.png) [@ematrix](https://forum.kirupa.com/u/ematrix)\
**Post date:** [September 18, 2011, 10:50am UTC](https://forum.kirupa.com/t/checking-if-child-exists/324965/1 "2011-09-18T10:50:25Z")

</div>

Hey Guys I am trying to check if a MC is on the screen but it says:

1120: Access of undefined property newBullet.

The code that is giving the error is in engine.as

```auto
if(stage.getChildByName(newBullet)) { newBullet.y = gtip.y;
				newBullet.x = gtip.x;
			}

```

gtip is an instance name of a movie clip that is in the character when it gets loaded

Here is the code from the files;

Engine.as

```auto
package code {
	
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	
	public class Engine extends MovieClip {
		
		
		public function Engine() {
			// constructor code
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

		}
					

		public function onAddedToStage(event:Event){
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			//Creating object of the character from the Character Class
			var myChar:Character = new Character();
			
			//Adding the character to the stage
			stage.addChild(myChar);
			
			//Setting the characters position
			myChar.y = stage.stageHeight / 3;
			myChar.x = stage.stageWidth / 2;
			
			if(stage.getChildByName(newBullet)) {
				newBullet.y = gtip.y;
				newBullet.x = gtip.x;
			}
	
		}
	}
	
}

```

Character.as (Code to add the bullet)

```auto
		public function mouseClickHandler(event:MouseEvent):void{
			trace("click");
			var myBullet:Bullet = new Bullet();
			stage.addChild(myBullet);
		}

```

Bullet.as

```auto
package code {	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	
	public class Bullet extends MovieClip {
		
		
		public function Bullet() {
			
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

		}
		
		public function onAddedToStage(event:Event){
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
	
		}
	}
	
}

```

Any help would be appreciated.

Thanks guys!
