2010-08-31 98 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