代码
stage.frameRate
=
100
;
var old: int = new Date().getTime();
var gt: int = getTimer();
var ot: int = old;
var t: int ;
var timer:Timer = new Timer( 1 );
timer.addEventListener(TimerEvent.TIMER,test);
timer.start();
function test(e:TimerEvent): void
{
var dx: int = new Date().getTime();
var dx2: int = getTimer();
if ( dx2 >= 1000 )
{
timer.stop();
trace(t , dx - ot ,dx2);
return ;
}
trace(dx - old , dx2 - gt);
old = dx;
gt = dx2;
t += 1 ;
}
var old: int = new Date().getTime();
var gt: int = getTimer();
var ot: int = old;
var t: int ;
var timer:Timer = new Timer( 1 );
timer.addEventListener(TimerEvent.TIMER,test);
timer.start();
function test(e:TimerEvent): void
{
var dx: int = new Date().getTime();
var dx2: int = getTimer();
if ( dx2 >= 1000 )
{
timer.stop();
trace(t , dx - ot ,dx2);
return ;
}
trace(dx - old , dx2 - gt);
old = dx;
gt = dx2;
t += 1 ;
}
输出结果(取后面):
15 2
0 2
0 3
0 2
0 1
0 1
0 2
0 2
16 2
0 2
0 3
0 2
0 2
0 2
0 2
16 2
0 2
0 1
0 2
0 2
0 1
464 1000 1000
测试结果:
getTimer()与系统时间是符合的.也就是说是准确的
实际timer的1毫秒根本达不到1000次,也就是timer并不准确
另外也可以看出FlashPlayer每15毫秒去取一次系统时间,并缓存起来