2016-07-27 71 views
-1

我做了很多搜索並找不到答案,請幫助我。 因此,我創建了一個名爲Snake Games的Flash遊戲,然後使用UILoader加載了另一個Flash遊戲,但是當我嘗試運行該Flash遊戲並檢查該Flash是否會加載該蛇遊戲時,我遇到了錯誤Adob​​e Flash ActionScript 3.0錯誤1009使用UILoader時

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at Main/addFood()

at Main/init()

at Main()

這裏的蛇遊戲 http://pastebin.com/raw/Z5ZBtLQn

內Main.as腳本煩請幫我。

謝謝。

回答

2

在你的情況下,null錯誤的來源是「舞臺不可用」。您需要將您的蛇遊戲構造函數更改爲第一個檢查階段,然後撥打init(),如下所示:

public function Main(){ 
     if (stage) init(); 
     else addEventListener(Event.ADDED_TO_STAGE,init); 
    } 
    function init(e:Event=null):void { 
     removeEventListener(Event.ADDED_TO_STAGE,init); 
     // rest of init() code