我已經創建了由兩個類組成的秒錶。首先是stopwatchModel。其次是stopwatchView。我的秒錶正在工作,但它顯示的時間比實際持續的時間少。看起來我的秒錶比現實慢。基於定時器顯示錯誤時間的秒錶AS3
StopwatchModel
private function initStopwatchModel():void{
timer = new Timer(100,0);
timer.addEventListener(TimerEvent.TIMER,onTimer);
}
private function onTimer(e:TimerEvent):void{
decsec++;
if (decsec == 10){
sec++;
decsec=0;
if (sec == 60){
sec = 0;
min++;
}
}
playerTimeString = min + ":" + sec + ":" + decsec + "0";
dispatchEvent(new Event("NEW_TIME"));
}
StopwatchView
private function initModelEventListeners(){
_model.addEventListener("NEW_TIME",onNewTime);
}
//update textoveho pola, vzdy ked sa zmeni cas
private function onNewTime(e:Event):void{
textFieldStopWatch.text = _model.playerTimeString;
}
謝謝你的答案