2013-03-09 57 views
-2

我真的不知道什麼是錯的。我一遍又一遍地得到同樣的錯誤。第31,32和46行的未定義屬性OneSecTimer的訪問。這是我第一次用Flash編碼,因此我真的不知道這裏發生了什麼。 OnTimeComplete被認爲是私有的,但是這就是爲什麼不能被訪問?未定義財產訪問oneSecTimer

包{

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

你有拼寫錯誤

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

應該

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

(您錯過了e

當你得到一個關於失蹤的屬性是一個錯誤,你一般應做的第一件事就是去,你認爲你定義它並確保它被定義,這正是你所期望的方式,它是:)

+0

哦,上帝,我覺得自己很愚蠢。這個鍵盤有嚴重的重影。感謝您的幫助! – user1580598 2013-03-09 15:50:28

+0

如果我的答案解決了你的問題,請考慮接受吧 – 2013-03-09 15:50:51

+0

我會的,我要等8分鐘哈哈 – user1580598 2013-03-09 15:52:16