import flash.utils.setInterval; import flash.utils.clearInterval; // 设置多少毫米触发 private var intervalDuration:Number = 1000; // 记录开启的计时器 private var intervalId:uint; //累加执行次数 private var counter:uint = 0; //目标执行次数 private var stopCount:uint = 3; /** * 是否添加 时间侦听 * @param _isAdd 默认是 */ public function addTimeInterval(_isAdd:Boolean = true){ if (_isAdd){ addTimeInterval(false); intervalId = setInterval(myRepeatingFunction, intervalDuration); //intervalId = setInterval(myRepeatingFunction, intervalDuration, "Hello", "World"); }else{ if(intervalId>0) { clearInterval(intervalId); } } } /** * 时间到触发 */ public function myRepeatingFunction():void { //trace(arguments[0] + " " + arguments[1]); counter++; if(counter == stopCount) { //trace("Clearing Interval"); addTimeInterval(false); } }
import flash.utils.setInterval; import flash.utils.clearInterval; // 设置多少毫米触发 var intervalDuration: Number = 1000; // 记录开启的计时器 var intervalId: uint; //累加执行次数 var counter: uint = 0; //目标执行次数 var stopCount: uint = 3; /** * 是否添加 时间侦听 * @param _isAdd 默认是 */ function addTimeInterval(_isAdd: Boolean = true) { if (_isAdd) { addTimeInterval(false); intervalId = setInterval(myRepeatingFunction, intervalDuration); //intervalId = setInterval(myRepeatingFunction, intervalDuration, "Hello", "World"); } else { if (intervalId > 0) { clearInterval(intervalId); } } } /** * 时间到触发 */ function myRepeatingFunction(): void { //trace(arguments[0] + " " + arguments[1]); counter++; if (counter == stopCount) { //trace("Clearing Interval"); addTimeInterval(false); } }