-
Notifications
You must be signed in to change notification settings - Fork 1
/
RenderClock.as
51 lines (41 loc) · 1.14 KB
/
RenderClock.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Static class
* Attempts to render the screen at a specified interval
* Dispatches an event at that interval
*/
package toolbox {
import flash.events.*;
import flash.utils.*;
public class RenderClock {
// public function RenderClock() {}
public static function frameRendered( e:Event ):void {
timeTick( null );
}
public static function start( hertz:int ):void {
__msTarget = 1000 / hertz;
destroy();
__previousTime = getTimer();
__timer = new Timer( __msTarget );
__timer.addEventListener( TimerEvent.TIMER, timeTick );
__timer.start();
}
public static function destroy():void {
if( __timer != null ) {
__timer.stop();
__timer.removeEventListener( TimerEvent.TIMER, timeTick );
__timer = null;
}
}
private static var __previousTime:int;
private static var __msTarget:Number;
private static var __timer:Timer;
private static function timeTick( e:TimerEvent ):void {
__timer.reset();
__timer.start();
EventHandler.getInstance().dispatchEvent( new ToolboxEvent( ToolboxEvent.RENDERCLOCK_TICK ) );
if( e != null ) {
e.updateAfterEvent();
}
}
}
}