Skip to content

Instantly share code, notes, and snippets.

@skyboy
Created July 18, 2011 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyboy/1088992 to your computer and use it in GitHub Desktop.
Save skyboy/1088992 to your computer and use it in GitHub Desktop.
public class Time {
import flash.utils.getQualifiedClassName;
public static const TIME_IS_INTRINSIC:int = 0;
public static const TIME_IS_EXTRINSIC:int = 1;
private static const CLASSNAME:String = getQualifiedClassName(new Time());
protected var paused:Boolean;
protected var lastTime:uint;
protected var accumulated:uint;
public function Time():void {
if (getQualifiedClassName(this) == CLASSNAME) throw new Error("Not allowed to instaniate abstract " + CLASSNAME + " object.");
}
public function get now():uint {
if (!paused) lastTime = getTimer() - accumulated;
else accumulated = getTimer() - lastTime;
return lastTime;
}
public function pause():void { paused = true; }
public function resume(timeMult:int):void {
throw new Error("Method \"resume\" must be defined by child classes.");
}
public function get tick():ISignal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment