Hi there! I am experiencing an issue in AS3 that doesn’t seem like it should be one at all…
In my document class I have the following snippet of code…
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class DocumentClass extends MovieClip
{
public var menuScreen:MenuScreen;
public var aoxGame:AoxGame;
public var manualScreen:ManualScreen;
public function DocumentClass()
{
showMenuScreen();
}
public function showMenuScreen():void
{
menuScreen = new MenuScreen();
menuScreen.x = 0;
menuScreen.y = 0;
addChild( menuScreen );
menuScreen.execute_btn.addEventListener(MouseEvent.CLICK, executeClick);
menuScreen.manual_btn.addEventListener(MouseEvent.CLICK, manualClick);
}
public function executeClick(e:MouseEvent):void
{
aoxGame = new AoxGame(stage);
aoxGame.x = 0;
aoxGame.y = 0;
addChild(aoxGame);
removeChild(menuScreen);
menuScreen = null;
}
function manualClick(e:MouseEvent):void
{
manualScreen = new ManualScreen();
manualScreen.x = 0;
manualScreen.y = 0;
addChild(manualScreen);
removeChild(menuScreen);
menuScreen = null;
}
}
}
Both ManualScreen and AoxGame are exported for actionscript and the instance names of execute_btn and manual_btn are on all three keyframes of their animations…yet only executeClick responds.
Every time I run my program I receive the following error (if “menuScreen.manual_btn.addEventListener(MouseEvent.CLICK, manualClick);” isn’t commented out):
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DocumentClass/showMenuScreen()
at DocumentClass$iinit()
I also applied a trace statement of “Working?” within the MenuScreen class file and it shows up before the error does! (Even though I don’t click on anything…)
Any ideas?
Thanks in advance!