我在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