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
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
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)
public function mouseClickHandler(event:MouseEvent):void{
trace("click");
var myBullet:Bullet = new Bullet();
stage.addChild(myBullet);
}
Bullet.as
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!