很好用
import flash.utils.Timer;
import flash.events.TimerEvent;
var myTimer:Timer = new Timer(1000, ;
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.addEventListener("timerComplete",timerEnd)
myTimer.start();
function detectProperty(){
//运行状态
trace(myTimer.running)
//间隔时间
trace(myTimer.delay)
//已经运行次数
trace(myTimer.currentCount)
//总共重复次数
trace(myTimer.repeatCount)
}
function timerHandler(event:TimerEvent):void {
trace("timerHandler: " + event);
var n=event.target.currentCount
if(n==5){
//复原到初始状态
myTimer.reset()
detectProperty()
//从头开始
myTimer.start()
}
}
function timerEnd(event:TimerEvent):void{
trace("timerHandler: " + event);
}
var timerState=true
timer_btn.addEventListener("click",clickFunc)
function clickFunc(event:Event){
if(timerState){
myTimer.stop()
}else {
myTimer.start()
}
timerState=!timerState
}
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/1793.html