0
我使用針對AS2編寫的教程在AS3中創建了一個遊戲,但我無法使計時器正常工作。遊戲包含3幀,開始屏幕,遊戲循環和結束屏幕。定時器從第2幀開始,然後倒計時(用跟蹤測試)。當計時器達到0時,我想轉到第3幀,這是結束遊戲屏幕,但我的代碼不工作。Actionscript 3倒計時器不會在文本框中顯示時間,並且當計時器達到0時什麼都不會發生。
var fl_SecondsToCountDown:Number = 30;
var fl_CountDownTimerInstance:Timer = new Timer(1000, fl_SecondsToCountDown);
fl_CountDownTimerInstance.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler);
fl_CountDownTimerInstance.start();
theTimer.text = String(fl_SecondsToCountDown);
function fl_CountDownTimerHandler(event:TimerEvent):void
{
if(fl_SecondsToCountDown == 0){;
gotoAndPlay(3);
}else{
trace(fl_SecondsToCountDown + " seconds");
fl_SecondsToCountDown--;
}
}
我的第二個問題是,ny timer(theTimer)沒有顯示時間。
編輯:
var running:Boolean = new Boolean();
running = false;
var time:Number = new Number();
var fl_SecondsToCountDown:Number = 30;
var fl_CountDownTimerInstance:Timer = new Timer(1000, fl_SecondsToCountDown);
fl_CountDownTimerInstance.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler);
fl_CountDownTimerInstance.start();
function fl_CountDownTimerHandler(event:TimerEvent):void
{
time=fl_SecondsToCountDown;
if(time == 0){
running = false;
trace(running);
gotoAndStop(3);
}else{
trace(fl_SecondsToCountDown + " seconds");
fl_SecondsToCountDown--;
theTimer.text = String(fl_SecondsToCountDown);
}
}
是否確定在設置該值時存在定時器? – zzzzBov 2011-01-24 17:19:41
程序中存在拼寫錯誤:if(fl_SecondsToCountDown == 0){;當您更改fl_SecondsToCountDown變量時,您的textField也不會自行更新。 – TheDarkIn1978 2011-01-24 17:55:48