page 30 repeating a task over time

package
{
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.getTimer;
	import flash.utils.Timer;
	
	/**
	 * ...
	 * @author
	 */
	public class Main extends Sprite
	{
		private var _previousTime:Number = 0;
		
		public function Main()
		{
			var tTimer:Timer = new Timer(500, 10);
			tTimer.addEventListener(TimerEvent.TIMER, onTimer);
			tTimer.start();
		}
		
		private function onTimer(event:TimerEvent):void
		{
			trace(getTimer() - _previousTime);
			_previousTime = getTimer();
		}
	}
}
//输出结果很奇怪。为什么每次输出都不一样的?


你可能感兴趣的:(【读书笔记】AS3,CookBook)