forked from: Date と getTimer()

by mezumona forked from Date と getTimer() (diff: 29)
...
@author mezumona (source : jc at bk-zen.com)
♥0 | Line 56 | Modified 2009-11-27 21:31:31 | MIT License
play

ActionScript3 source code

/**
 * Copyright mezumona ( http://wonderfl.net/user/mezumona )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fDue
 */

// forked from bkzen's Date と getTimer()
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.getTimer;
	
	/**
	 * ...
	 * @author mezumona (source : jc at bk-zen.com)
	 */
	[SWF (backgroundColor = "0xFFFFFF", frameRate = "60", width = "465", height = "465")]
	public class Test2 extends Sprite
	{
		private var txt: TextField;
		private var startTimeA: uint;
		private var startTimeB: uint;
		private var previousTimeA: uint = 0;
		private var previousTimeB: uint = 0;
		private var startDiff: uint;
		private var count: int;
		
		public function Test2() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e: Event = null): void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			//
			txt = new TextField();
			txt.autoSize = TextFieldAutoSize.LEFT;
			addChild(txt);
	    	startTimeA = getTimer();
		    startTimeB = new Date().getTime();
			addEventListener(Event.ENTER_FRAME, loop);
		}
		
		private function loop(e: Event ): void 
		{
			if (count++ % 30 == 0) {
    			var tA: uint = getTimer();
			    var tB: uint = new Date().getTime();

			    var lA: uint = tA - startTimeA;
			    var lB: uint = tB - startTimeB;
			    var dA: uint = tA - previousTimeA;
			    var dB: uint = tB - previousTimeB;

			    previousTimeA = tA;
			    previousTimeB = tB;
    			txt.text = "getTimer() : " + lA
    			         + " (diff : " + dA
    			         + ")\nnew Date() : " + lB
    			         + " (diff : " + dB
    			         + ")\n---"
    			         + "\ncurrentDiff : " + (dA - dB)
    			         + "\ntotalDiff : " + (lA - lB);
    			txt.x = (stage.stageWidth - txt.width) / 2;
    			txt.y = (stage.stageHeight - txt.height) / 2;
			}
		}
		
	}

}