/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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(); } } }
URL: http://blog.funciton.com/2009/09/timer-with-a-pause-and-resume.html