2

TypeError: Error #1010当我试图在 AS3 中为一个小游戏创建构造函数代码时,我不断得到。似乎导致问题的代码是:

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()
4

1 回答 1

2

我看不出代码本身有什么问题。我猜测其中一个影片剪辑screen1没有screen6定义命名按钮,或者StartScreenetc 类不存在或无法访问。

于 2012-11-18T10:31:49.463 回答