AS3 stage = null?

后端 未结 3 1305
孤独总比滥情好
孤独总比滥情好 2021-01-21 05:48

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

相关标签:
3条回答
  • 2021-01-21 06:21

    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.

    0 讨论(0)
  • 2021-01-21 06:25
    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.

    0 讨论(0)
  • 2021-01-21 06:30

    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.

    0 讨论(0)
提交回复
热议问题