I’m getting this error when I click the start button from the main menu.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Player()[C:\Users\Brandon\Desktop\Player.as:21]
at Engine()[C:\Users\Brandon\Desktop\Engine.as:13]
at MainMenu/playGame()[C:\Users\Brandon\Desktop\MainMenu.as:19]
package {
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
public class MainMenu extends MovieClip {
public function MainMenu()
{
startButton.addEventListener(MouseEvent.MOUSE_DOWN, playGame, false, 0, true);
}
private function playGame(event:MouseEvent) : void
{
var engine:Engine = new Engine(stage);
gotoAndStop(2);
}
}
}
package
{
import flash.events.*;
import flash.utils.Timer;
import flash.display.*;
public class Engine extends MovieClip
{
private var stageRef:Stage;
public static var enemyArray:Array = new Array();
public var scoreHUD:ScoreHUD = new ScoreHUD(stageRef);
var player:Player = new Player(stageRef);
private var myTimer:Timer = new Timer(1000);
var i:Number = 1;
public function Engine(stageRef:Stage)
{
this.stageRef = stageRef;
stageRef.addEventListener(Event.MOUSE_LEAVE,go);
myTimer.addEventListener(TimerEvent.TIMER, timerFunction);
myTimer.start();
createEnemies();
stageRef.addChild(player);
player.x = stageRef.stageHeight / 2;
player.y = stageRef.stageWidth / 2;
}
........