我在Adobe Flash Professional CS5中构建项目(使用ActionScript 3.0)。舞台何时加载?
在其中一个类中,我想根据场景的大小向场景添加一些对象。
我使用构造函数中的以下代码:
stageWidthint = stage.stageWidth;
stageHeightint = stage.stageHeight;
startMenu.x = stageWidthint/2;
startMenu.y = ((stageHeightint/2) - 40);
instructionsMenu.x = stageWidthint/2;
instructionsMenu.y = ((stageHeightint/2) + 2);
highscoreMenu.x = stageWidthint/2;
highscoreMenu.y = ((stageHeightint/2) + 44);
quitMenu.x = stageWidthint/2;
quitMenu.y = ((stageHeightint/2) + 86);
this.addChild(startMenu);
this.addChild(instructionsMenu);
this.addChild(highscoreMenu);
this.addChild(quitMenu);
我得到的stage
空引用。经过快速搜索,我发现当时尚未加载stage
。不过,我想把这些孩子加入课堂。舞台什么时候加载?如何解决这个问题,并在游戏开始时仍显示所有内容?
Event.ADDED_TO_STAGE – 2013-03-11 20:17:20
好的,谢谢,这解决了我的问题。我将所有这些东西放在事件处理程序调用的方法中。但是,什么时候加载完成?这是几秒钟或什么事情? – Joetjah 2013-03-11 20:24:27
Downvoter,关心发表评论? – Joetjah 2013-03-12 14:44:03