2013-03-07 53 views
0

我正在進行問答遊戲,涉及5個問題。我爲第一個問題做了一個計時器,所以當用戶在10秒內沒有回答這個問題時,他們會回答問題2(另一個框架)。 問題1計時器工作正常,我如何得到問題2與問題1完全相同?我試圖在問題2中添加相同的代碼,但它給了我一個錯誤。
感謝多個計時器幫助! FLASH as3

我的代碼:

stop(); 

var count:Number = 10; 
var myTimer:Timer=new Timer(1000,2); 
myTimer.addEventListener(TimerEvent.TIMER, countdown); 
myTimer.start(); 

function countdown(event:TimerEvent):void { 
count00.text=String((count)-myTimer.currentCount); 

if(count00.text == "0"){ 
gotoAndStop(85); 
} 
} 


myTimer.stop(); 
myTimer.removeEventListener(TimerEvent.TIMER, countdown); 

回答

1

首先,你不應該被過度multible幀這樣做。但那是一個不同的討論。

您應該停止計時器,刪除監聽器並移動到onComplete事件中的下一幀。

stop(); 

var count:Number = 10; 
var myTimer:Timer=new Timer(1000,count);// this should be the total count 
myTimer.addEventListener(TimerEvent.TIMER, countdown); 
myTimer.addEventListener(TimeEvent.TIMER_COMPLETE, timerDone); 
myTimer.start(); 

function countdown(event:TimerEvent):void { 
    count00.text=String((count)-event.currentTarget.currentCount);//get currentCount from event 
} 

function timerDone(e:TimerEvent):void{ 
    trace("Timer finishing!"); 
    myTimer.stop(); 
    myTimer.removeEventListener(TimerEvent.TIMER, countdown); 
    gotoAndStop(85); 
} 

Btw。您在計時器的repeatCount設置爲2,new Timer(1000,2);這會給你2秒倒計時,沒有太多的時間問題;)應該是count

也有musst是一個動態文本與在實例名稱count00與代碼一樣的框架(不是圖層)!

請在問題中始終包含相關錯誤信息!

+0

TypeError:錯誤#1009:無法訪問空對象引用的屬性或方法。 \t在product_fla :: MainTimeline /倒計時() \t在flash.utils ::定時器/ _timerDispatch() \t在flash.utils ::定時器/蜱() – Jen 2013-03-07 12:47:05

+0

我現在得到這個。怎麼了? – Jen 2013-03-07 12:48:06

+0

你之前得到什麼錯誤? – M4tchB0X3r 2013-03-07 12:51:25