TypeError:错误#1006:addEventListener不是函数

时间:2015-06-10 09:08:17

标签: actionscript-3

Flash新手,只是想完成一项任务。 带有开始和结束屏幕的简单导航界面。我有那个工作。代码很简单。

现在我尝试将this教程插入到我的一个框架/页面中。 目前我在标题中收到错误,但无论如何,这是代码。

package 
{
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.utils.setTimeout;
    import flash.utils.getTimer;

    public class MathGameFinal extends MovieClip
    {
        private var buttonsArray:Array = new Array();
        private var num1Array:Array = new Array();
        private var num2Array:Array = new Array();
        private var answersArray:Array = new Array();
        private var count:uint = 0;
        private var numOfQuestions:uint = 20;
        private var numRange:uint = 20;
        private var startTime:uint;
        private var currentTime:uint;

        public function MathGameFinal()
        {
            // constructor code
            buttonsArray = new Array(oneBtn,twoBtn,threeBtn,fourBtn,
            fiveBtn,sixBtn,sevenBtn,eightBtn, nineBtn, zeroBtn, clearBtn);

            for (var i:uint = 0; i < buttonsArray.length; i++)
            {
                buttonsArray[i].buttonMode = true;
                buttonsArray[i].addEventListener(MouseEvent.CLICK, buttonClicked);
            }

            mgEnd_Screen.visible = false;

            mgStart_Screen.mgStart_Btn.addEventListener(MouseEvent.CLICK, startGame);
        }

        private function startGame(e:MouseEvent):void{
            mgStart_Screen.visible = false; 
            init();
        }

        private function init():void { 
            startTime = getTimer();
            currentTime = 0;

            for(var j:uint = 0;  j < numOfQuestions; j++){
                num1Array.push( uint(Math.random() * numRange)+1 );
                num2Array.push( uint(Math.random() * numRange)+1 );
                answersArray.push( num1Array[j] + num2Array[j] );
            }
            Input_Txt.text = num1Array[count] + ' + ' + num2Array[count];  
        }

        private function buttonClicked(e:MouseEvent):void{
            switch(e.target){
             case zeroBtn: Output_Txt.appendText('0'); break;
             case oneBtn:   Output_Txt.appendText('1'); break;
             case twoBtn:  Output_Txt.appendText('2'); break;
             case threeBtn:  Output_Txt.appendText('3'); break;
             case fourBtn:  Output_Txt.appendText('4'); break;
             case fiveBtn:  Output_Txt.appendText('5'); break;
             case sixBtn:  Output_Txt.appendText('6'); break;
             case sevenBtn: Output_Txt.appendText('7'); break;
             case eightBtn:  Output_Txt.appendText('8'); break;
             case nineBtn:  Output_Txt.appendText('9'); break;
             case clearBtn:  Output_Txt.text ='';     break;
            }
            setTimeout(checkResult,400);
        }
        private function checkResult():void{
            if(Output_Txt.text == answersArray[count]){
            Output_Txt.text = ''};
            count++;
            Input_Txt.text = num1Array[count] + ' + ' + num2Array[count];
        }
    }
}

0 个答案:

没有答案