View Full Version : Event Listener trouble - Flash AS3.0

03-16-2008, 05:18 PM
Hey all,

Having a bit of trouble with my menu. I have buttons located on 3 different scenes in the FLA, and want to link between them. All my code is located on one AS file.

My code setup is as follows:

In the main function I have my even listeners. For example, for the "help" button:

help_btn.addEventListener(MouseEvent.MOUSE_UP, helpPressed); Which calls the "helpPressed" function:

public function helpPressed(myEvent:MouseEvent):void {
gotoAndPlay(1, "Help");
} Which goes to frame 1 of the "Help" scene.

Now on the "Help" scene, I have another button called "help_rtn", which is to return to the main menu. Again, I have an event listener:

help_rtn.addEventListener(MouseEvent.MOUSE_UP, helpRtnPressed);

and the function:

public function helpRtnPressed(myEvent:MouseEvent):void {
gotoAndPlay(1, "MainMenu");

But as this button is not on the first scene, I get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MenuInit$iinit()

I think this has something to do with the event listerners, and that I must define what scene the button is on. But I have no idea how to do this... can someone help me?