TypeError:AS3构造函数代码中的错误#1010

时间:2012-11-17 17:18:55

标签: actionscript-3 flash typeerror

在尝试为AS3中的小游戏创建构造函数代码时,我不断获得TypeError: Error #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 个答案:

答案 0 :(得分:2)

我没有看到代码本身有任何问题。我猜测其中一个动画片段screen1screen6没有定义命名按钮,或StartScreen等类不存在或无法访问。