letting timer speed go faster as time passes
I would like to use a timer which goes faster while it runs. I tried the following:
开发者_Python百科var timerSpeed:uint = 50;
var timer:Timer = new Timer(1000-timerSpeed, numStates);
timer.addEventListener(TimerEvent.TIMER, timerimerHandler);
timer.start();
private function timerHandler(e:TimerEvent):void{
timerSpeed+=50;
}
but this isn't working since a variable is only created once.
How can I fix this?
Always refer to the official documentation, which is very good: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/Timer.html
Here is an example:
var timer:Timer = new Timer(1000, 10);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
function timerHandler(e:TimerEvent):void{
timer.delay = (timer.delay - 50);
}
If you check, you'll see that at the 10th run, the delay will be 500ms, which is the behavior you want.
精彩评论