Skip to content

Instantly share code, notes, and snippets.

@ggendre
Created April 5, 2011 13:27
Show Gist options
  • Save ggendre/903578 to your computer and use it in GitHub Desktop.
Save ggendre/903578 to your computer and use it in GitHub Desktop.
tryTimer : a function to test time accuracy for a target of 1080ms. see http://ggendre.posterous.com/flash-time-accuracy for details
private function tryTimer():void{
var delay:uint=40;// <--- change this
var t = new Timer(delay);
var tNormal:uint=0
var tReal:uint=0
var lastDate:Date = new Date();
t.addEventListener(TimerEvent.TIMER, function():void{
var today:Date = new Date();
var diff:Number=today.getTime()-lastDate.getTime();
tNormal+=delay;
tReal+=diff;
lastDate=today;
if (tNormal>=1080){
log.text+='\n'+ String(tReal-tNormal);
t.stop();
}
});
t.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment