Revision: 17996
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 19, 2009 14:19 by arpit
Initial Code
package inca.utils {
import flash.utils.Timer;
public class TimerAdv extends Timer {
private var $__initDelay:Number = 0;
private var $__pauseTime:Number = 0;
private var $__acumulado:Number = 0;
private var $__startingTime:Number = NaN;
private var $__paused:Boolean = false;
public function TimerAdv(delay:Number, repeatCount:uint = 0){
$__initDelay = delay;
super(delay, repeatCount);
}
public function get paused():Boolean{ return $__paused; }
override public function start():void{
if($__paused){
resume();
}else{
$__startingTime = new Date().getTime();
super.start();
}
}
override public function reset():void{
delay = $__initDelay;
$__acumulado = 0;
$__pauseTime = 0;
super.reset();
}
public function pause():void{
if(isNaN($__startingTime)) throw new Error("You can't call TimerAdv.pause() without calling TimerAdv.start() first.")
super.stop();
$__paused = true;
$__pauseTime = new Date().getTime();
}
public function resume():void{
$__paused = false;
delay = Math.max(0, ($__initDelay - (($__pauseTime - $__startingTime) + $__acumulado)));
$__acumulado += ($__pauseTime - $__startingTime);
start();
}
}
}
Initial URL
http://blog.funciton.com/2009/09/timer-with-a-pause-and-resume.html
Initial Description
Initial Title
Timer with resume
Initial Tags
Initial Language
ActionScript 3