访问未定义属性oneSecTimer

时间:2013-03-09 15:45:06

标签: flash timer

我真的不知道出了什么问题。我一遍又一遍地继续得到同样的错误。访问第31,32和46行的未定义属性OneSecTimer。这是我第一次使用Flash进行编码,所以我真的不知道这里发生了什么。 OnTimeComplete被认为是私有的,但这就是为什么不能访问的东西?

包{

import flash.display.MovieClip;

import flash.events.TimerEvent;
import flash.utils.Timer;


public class MainTimer extends MovieClip {
    // Init vars for class
    private var currentMin:int;
    private var currentSec:int;
    // create a one second timer from Flash's Timer class
    private var onSecTimer:Timer = new Timer(1000,1);            

    public var timerHasStopped:Boolean = false;

    public function MainTimer() {
        // constructor code
        trace("the main timer is here");
        currentMin= 2;
        currentSec = 5;

        minBox.text = String(currentMin);
        if(currentSec < 10){
            secBox.text = "0" + String(currentSec);
        }else{
            secBox.text = String(currentSec);
        }

        oneSecTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
        oneSecTimer.start();
    }

    private function onTimerComplete(event:TimerEvent):void{
        currentSec = currentSec - 1;
        if (currentSec < 0){
            currentSec = 59;
            currentMin -= 1;
        } //end if
        if(currentMin < 0){
            currentMin = 0;
            currentSec = 0;
            timerHasStopped = true;
        }else{
            oneSecTimer.start();
        } //end else

        //update the display
        minBox.text = String(currentMin);
        secBox.text = String(currentSec);
        if(currentSec < 10){
            secBox.text = "0" + String(currentSec);
        }//end if                

    }//end function 

}

}

1 个答案:

答案 0 :(得分:1)

您有拼写错误

private var onSecTimer:Timer = new Timer(1000,1);        

应该是

private var oneSecTimer:Timer = new Timer(1000,1);            

(你错过了e

当你收到关于遗失属性的错误时,你通常应该做的第一件事是去你认为你定义它的地方,并确保它的确定方式与你预期的完全相同:)