Timer计数器(模拟JAVA Thread)

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()
}

你可能感兴趣的:(thread,timer,AS)