2010-08-31 99 views
2

我有一個計時器警報:計時器警報 - 修正

private var cheat:Timer; 

private function init():void { 
    cheat = new Timer(2000, 1); 
    cheat.addEventListener(TimerEvent.TIMER_COMPLETE, cheatProtection); 
} 

private function showAlert():void { 
    cheat.reset(); 
    cheat.start(); 
} 
private function alrt_close(evt:CloseEvent):void { 
    cheat.stop(); 
} 

private function cheatProtection(evt:TimerEvent):void { 
    Alert.show("Text", "Label", Alert.OK, this, alrt_close); 
} 

所以,我做的是我叫出來showAlert(),但警報(cheatProtection功能)不會發生。哪裏不對?

感謝,顏

+0

你是在你調用類的地方調用的init(),對不對? – 2010-08-31 20:19:27

+0

嗯..我在做: rollOut =「showAlert()」 東西不見了? – Yan 2010-08-31 20:48:50

+2

對,但是你在某個時候明確地調用了init()嗎?如果沒有,你的計時器永遠不會被創建。 (除非init()被自動調用;它已經有一段時間了,因爲我創建了一個Flex對象。) – 2010-08-31 21:03:05

回答

1

應該是:

private var cheat:Timer; 

private function init():void { 
    cheat = new Timer(2000, 1); 
    cheat.addEventListener(TimerEvent.TIMER_COMPLETE, cheatProtection); 
    cheat.start(); 
} 

private function showAlert():void { 
    cheat.reset(); 
    cheat.start(); 
} 
private function alrt_close(evt:CloseEvent):void { 
    cheat.stop(); 
} 

private function cheatProtection(evt:TimerEvent):void { 
    Alert.show("Text", "Label", Alert.OK, this, alrt_close); 
} 
init(); 
+0

仍然是一樣的,沒有變化 – Yan 2010-08-31 20:48:15

+0

再試一次,我已經更新 – Eugene 2010-08-31 20:56:28

+0

不幸的是, t工作 – Yan 2010-08-31 21:01:17

0

不知道,如果這會有所幫助,但Adobe Flex的文檔中的TimerEvent監聽器啓動後添加()被調用。

+0

不會改變任何東西... – Yan 2010-08-31 20:42:21