用的时候直接调用onTimeHandler 和transadvanceTime函数
private function onTimeHandler():void
{
if(timer == null)//时间为空时,附上时间
{
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,onTimer);
timer.start();
}
}
private function onTimer(event:TimerEvent):void
{
if(t>0)
{
t--;
//赋给要显示的组件ID上
cd.text=transadvanceTime(t);
}
else
{
timer.stop();
//时间停止时移除自身
timer.removeEventListener(TimerEvent.TIMER,onTimer);
timer = null;
}
}
//时分秒的操作转化
private function transadvanceTime(timeNum:Number):String
{
var total_seconds:uint = Math.floor(timeNum);
var total_minutes:uint = Math.floor(total_seconds/60);
var total_hours:uint = Math.floor(total_minutes/60);
var total_days:uint = Math.floor(total_hours/24);
var days:uint = total_days;
var hours:uint = total_hours%24;
var minutes:uint = total_minutes%60;
var seconds:uint = total_seconds%60;
return (hours<10?"0"+hours:hours.toString())+":"+(minutes<10?"0"+minutes:minutes.toString())+":"+(seconds<10?"0"+seconds:seconds.toString());
}