| 10 | * @author Jim Chen |
| 11 | */ |
| 12 | export class MotionManager { |
| 13 | private _isRunning:boolean = false; |
| 14 | private _ttl:number; |
| 15 | private _dur:number; |
| 16 | private _parent:DisplayObject; |
| 17 | private _timer:Runtime.Timer; |
| 18 | private _timeKeeper:Runtime.TimeKeeper; |
| 19 | private _independentTimer:boolean; |
| 20 | private _tween:Tween.ITween; |
| 21 | public oncomplete:Function = null; |
| 22 | |
| 23 | constructor(o:DisplayObject, |
| 24 | dur:number = 1000, |
| 25 | independentTimer:boolean = false) { |
| 26 | |
| 27 | if (typeof o === 'undefined' || o === null) { |
| 28 | throw new Error('MotionManager must be bound to a DisplayObject.'); |
| 29 | } |
| 30 | |
| 31 | this._ttl = dur; |
| 32 | this._dur = dur; |
| 33 | this._parent = o; |
| 34 | this._independentTimer = independentTimer; |
| 35 | this._timeKeeper = new Runtime.TimeKeeper(); |
| 36 | |
| 37 | var self = this; |
| 38 | if (this._independentTimer) { |
| 39 | this._timer = new Runtime.Timer(41, 0); |
| 40 | this._timer.addEventListener('timer', () => { |
| 41 | self._onTimerEvent(); |
| 42 | }); |
| 43 | this._timer.start(); |
| 44 | } else { |
| 45 | this._parent.addEventListener('enterFrame', () => { |
| 46 | self._onTimerEvent(); |
| 47 | }); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | set dur(dur:number) { |
| 52 | this._timeKeeper.reset(); |
| 53 | this._ttl = dur; |
| 54 | this._dur = dur; |
| 55 | } |
| 56 | |
| 57 | get dur():number { |
| 58 | return this._dur; |
| 59 | } |
| 60 | |
| 61 | get running():boolean { |
| 62 | return this._isRunning; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Private method invoked every time a timer event is fired |
| 67 | */ |
| 68 | private _onTimerEvent():void { |
| 69 | // Ignore timer events if this is not running |
nothing calls this directly
no outgoing calls
no test coverage detected