2012-11-17 53 views
2

嘗試爲AS3中的小遊戲創建構造函數代碼時,我總是得到TypeError: Error #1010。這似乎是導致該問題的代碼是:TypeError:AS3構造函數代碼中的錯誤#1010

package { 
import flash.display.MovieClip; 
import flash.events.MouseEvent; 

public class Main extends MovieClip { 
    var screen1:StartScreen; 
    var screen2:InstructionsScreen; 
    var screen3:SelectScreen; 
    var screen4:Game1Screen; 
    var screen5:Game2Screen; 
    var screen6:Game3Screen; 
    var screen7:FailScreen; 
    var screen8:CompleteScreen; 

    public function Main(){ 
     screen1 = new StartScreen(); 
     screen2 = new InstructionsScreen(); 
     screen3 = new SelectScreen(); 
     screen4 = new Game1Screen(); 
     screen5 = new Game2Screen(); 
     screen6 = new Game3Screen(); 
     screen7 = new FailScreen(); 
     screen8 = new CompleteScreen(); 

     screen1.startBtn.addEventListener(MouseEvent.CLICK,gotoSelect); 
     screen1.instBtn.addEventListener(MouseEvent.CLICK,gotoInst); 
     screen2.startBtn.addEventListener(MouseEvent.CLICK,gotoSelect2); 
     screen3.game1Btn.addEventListener(MouseEvent.CLICK,gotoGame1); 
     screen3.game2Btn.addEventListener(MouseEvent.CLICK,gotoGame2); 
     screen3.game3Btn.addEventListener(MouseEvent.CLICK,gotoGame3); 
     screen4.failBtn.addEventListener(MouseEvent.CLICK,gotoFail1); 
     screen4.winBtn.addEventListener(MouseEvent.CLICK,gotoWin1); 
     screen5.failBtn.addEventListener(MouseEvent.CLICK,gotoFail2); 
     screen5.winBtn.addEventListener(MouseEvent.CLICK,gotoWin2); 
     screen6.failBtn.addEventListener(MouseEvent.CLICK,gotoFail3); 
     screen6.winBtn.addEventListener(MouseEvent.CLICK,gotoWin3); 
     addChild(screen1); 
    } 
    private function gotoSelect(evt:MouseEvent):void{ 
     removeChild(screen1); 
     addChild(screen3); 
    } 
    private function gotoInst(evt:MouseEvent):void{ 
     removeChild(screen1); 
     addChild(screen2); 
    } 
    private function gotoSelect2(evt:MouseEvent):void{ 
     removeChild(screen2); 
     addChild(screen3); 
    } 
    private function gotoGame1(evt:MouseEvent):void{ 
     removeChild(screen3); 
     addChild(screen4); 
    } 
    private function gotoGame2(evt:MouseEvent):void{ 
     removeChild(screen3); 
     addChild(screen5); 
    } 
    private function gotoGame3(evt:MouseEvent):void{ 
     removeChild(screen3); 
     addChild(screen6); 
    } 
    private function gotoFail1(evt:MouseEvent):void{ 
     removeChild(screen4); 
     addChild(screen7); 
    } 
    private function gotoWin1(evt:MouseEvent):void{ 
     removeChild(screen4); 
     addChild(screen8); 
    } 
    private function gotoFail2(evt:MouseEvent):void{ 
     removeChild(screen5); 
     addChild(screen7); 
    } 
    private function gotoWin2(evt:MouseEvent):void{ 
     removeChild(screen5); 
     addChild(screen8); 
    } 
    private function gotoFail3(evt:MouseEvent):void{ 
     removeChild(screen6); 
     addChild(screen7); 
    } 
    private function gotoWin3(evt:MouseEvent):void{ 
     removeChild(screen6); 
     addChild(screen8); 
    } 
} 
} 

,當我嘗試和運行此出現的錯誤信息是:

TypeError: Error #1010: A term is undefined and has no properties. 
at Main() 
+1

你能否提供完整的'Main'類,以便我們可以確定導致錯誤的原因。上面的代碼似乎不是一個有問題的人 –

+0

當然,這是相當長的。 – Tummus

+3

對,我沒有看到代碼本身有什麼問題。我猜測影片剪輯「screen1」到「screen6」沒有定義命名按鈕,或者「StartScreen」等類不存在或可訪問。 –

回答

2

我看不出有什麼毛病代碼本身。我猜測其中一個影片剪輯screen1screen6沒有定義命名按鈕,或StartScreen等類不存在或可訪問。