1
8
9 import com.sekati.core.CoreObject;
10 import com.sekati.core.FWDepth;
11 import com.sekati.events.IPulsable;
12 import com.sekati.utils.ClassUtils;
13 import com.sekati.utils.Delegate;
14
15
18 class com.sekati.events.FramePulse extends CoreObject implements IPulsable {
19
20
21 private var addListener:Function;
22 private var removeListener:Function;
23 private var broadcastMessage:Function;
24 private var _listeners:Array;
25 private static var _instance:FramePulse;
26 private var _mc:MovieClip;
27 private var _f:Function;
28 public static var onEnterFrameEVENT:String = "_onEnterFrame";
29
30
33 private function FramePulse() {
34 AsBroadcaster.initialize( this );
35 _mc = ClassUtils.createEmptyMovieClip( com.sekati.display.BaseClip, _root, "___FramePulse", {_depth:FWDepth.FramePulse} );
36 _f = Delegate.create( this, broadcastMessage, onEnterFrameEVENT );
37 }
38
39
43 public static function getInstance():FramePulse {
44 if (!_instance) _instance = new FramePulse( );
45 return _instance;
46 }
47
48
51 public static function get $():FramePulse {
52 return FramePulse.getInstance( );
53 }
54
55
59 public function start():Void {
60 _mc.onEnterFrame = _f;
61 }
62
63
66 public function stop():Void {
67 _mc.onEnterFrame = null;
68 }
69
70
74 public function isRunning():Boolean {
75 return _mc.onEnterFrame == _f;
76 }
77
78
83 public function addFrameListener(o:Object):Void {
84 if (_listeners.length < 1) start( );
85 addListener( o );
86 }
87
88
93 public function addFrameListeners(a:Array):Void {
94 for(var i:Number = 0; i < a.length ; i++) {
95 addFrameListener( a[i] );
96 }
97 }
98
99
104 public function removeFrameListener(o:Object):Void {
105 removeListener( o );
106 if (_listeners.length < 1) stop( );
107 }
108
109
114 public function removeFrameListeners(a:Array):Void {
115 for(var i:Number = 0; i < a.length ; i++) {
116 removeFrameListener( a[i] );
117 }
118 }
119
120
124 public function isListenerRegistered(o:Object):Boolean {
125 for (var i in _listeners) if(_listeners[i] === o) return true;
126 return false;
127 }
128
129
133 public function destroy():Void {
134 _instance.stop( );
135 _mc.destroy( );
136 delete _instance;
137 super.destroy( );
138 }
139 }