forked from: Timerの実行間隔テスト
forked from Timerの実行間隔テスト (diff: 9)
ActionScript3 source code
/**
* Copyright hacker_9p8x8mco ( http://wonderfl.net/user/hacker_9p8x8mco )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/k8eF
*/
package {
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;
import flash.utils.getTimer;
public class TimerTest extends Sprite
{
private static const TIMER_INTERVAL:int = 1000;
private var timer:Timer;
private var _console:TextField;
private var lastStartTime:int = 0;
private var lastEndTime:int = 0;
public function TimerTest()
{
_console = new TextField();
_console.autoSize = TextFieldAutoSize.LEFT;
addChild(_console);
timer = new Timer(TIMER_INTERVAL, 0);
timer.addEventListener(TimerEvent.TIMER, handlerTimer);
timer.start();
}
private function handlerTimer(event:TimerEvent):void {
var startTime:int = getTimer();
log('handlerの開始: ' + startTime);
log(' 前回の開始時間との差: ' + (startTime - lastStartTime));
log(' 前回の終了時間との差: ' + (startTime - lastEndTime));
var counter:int = 0;
var interval:int = TIMER_INTERVAL * 0.8;
while((getTimer() - startTime) < interval) {
//時間のかかる処理をする
counter++;
}
lastStartTime = startTime;
lastEndTime = getTimer();
log('handlerの終了時間: ' + lastEndTime);
}
private function log(message:String):void {
_console.text = "test\n" + _console.text;
// _console.text = message + '\n' + _console.text;
}
}
}
