AS3 stage = null?

≯℡__Kan透↙ 提交于 2019-12-01 21:02:08
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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!