I\'ve just tried to implement a menu system I saw a tutorial onto a game that I\'m working on and it was all smooth sailing until I\'ve now encountered a problem with the stage
When you create the AvoiderGame object, it wil fire the constructor. at this time, the object is not added to the stage or any object in the display list, so it will not have any reference to the stage.
You can add a listener to the ADDED_TO_STAGE event or call a custom init
method before adding it to the stage manually.
public function AvoiderGame(callBack)
{
stage.addEventListener(Event.ADDED_TO_STAGE, init);
theCallBackFunction = callBack;
}
Should be something like
public function AvoiderGame(callBack)
{
this.addEventListener(Event.ADDED_TO_STAGE, init);
theCallBackFunction = callBack;
}
Don't forget to remove the event listener when the init function is called.
When a display object is not added to the stage or an other display object already in the display list, stage is null. Event.ADDED_TO_STAGE will be dispatched, when stage is set and available.