欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Timer计数器(模拟JAVA Thread)

程序员文章站 2022-05-05 21:20:38
...

var interval:uint=100
var repeat:uint=60
var myTimer:Timer=new Timer(interval,repeat)
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent):void
{
//得到Timer类的实例
var timer:Timer=event.target
//计算秒数
var t:Number=timer.currentCount/10
//保留1位小数
time.text=t.toFixed(1)
}

 

例子2:

 

var totalTime:int=60
var repeat:int=clockBar_mc.totalFrames
var interval:int=totalTime*1000/repeat
var myTimer:Timer=new Timer(interval,repeat)
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.start();
function timerHandler(event:TimerEvent):void
{
clockBar_mc.nextFrame()
}
over_btn.addEventListener(MouseEvent.CLICK,gameOver)
function gameOver(e:MouseEvent)
{
myTimer.stop()
}
restart_btn.addEventListener(MouseEvent.CLICK,gameRestart)
function gameRestart(e:MouseEvent)
{
clockBar_mc.gotoAndStop(1)
myTimer.reset()
myTimer.start()
}

相关标签: Timer AS Thread