TimeLineAnimation.as

Go to the documentation of this file.
00001 import gugga.animations.IAnimation;
00002 import gugga.collections.ArrayList;
00003 
00004 [Event("start")]
00005 [Event("interrupted")]
00006 [Event("completed")]
00007 class gugga.animations.TimeLineAnimation extends gugga.common.UIComponentEx implements IAnimation
00008 {       
00009         private var mIsRunning:Boolean = false;
00010         private var mDoLoop:Boolean = false;
00011         private var mHideAfterCompletion:Boolean = true;
00012 
00013         private var mCuePoints:Array;
00014         
00015         public function get DoLoop():Boolean { return mDoLoop; }
00016         public function set DoLoop(aValue:Boolean):Void { mDoLoop = aValue; }   
00017         
00018         public function get HideAfterCompletion():Boolean { return mHideAfterCompletion; }
00019         public function set HideAfterCompletion(aValue:Boolean):Void { mHideAfterCompletion = aValue; }
00020         
00021         public function getCuePointEventNames() : Array 
00022         {
00023                 var result : ArrayList = new ArrayList();
00024                 for (var i : Number = 0; i < mCuePoints.length; i++)
00025                 {
00026                         result.push(mCuePoints[i].event);
00027                 }
00028                 return result;
00029         }
00030         
00031         function TimeLineAnimation()
00032         {               
00033                 mCuePoints = new Array();
00034                 this.onEnterFrame = null;
00035 
00036                 stop();
00037                 hide();
00038         }
00039         
00040         public function addCuePoint(aFrame:Number, aEventName:String) : Void 
00041         {
00042                 mCuePoints.push({position:aFrame, event:aEventName});
00043                 mCuePoints.sortOn("position", Array.NUMERIC);
00044         }
00045         
00046         public function show():Void
00047         {
00048                 this._visible = true;
00049         }
00050         
00051         public function hide():Void
00052         {
00053                 this._visible = false;
00054         }
00055 
00056         public function start():Void
00057         {
00058                 if (!mIsRunning)
00059                 {
00060                         mIsRunning = true;
00061                         
00062                         dispatchEvent({type:"start", target:this});
00063                         
00064                         gotoAndStop(1);
00065                         
00066                         show();
00067                         this.play();
00068                 }
00069         }
00070         
00071         public function isRunning() : Boolean 
00072         {
00073                 return mIsRunning;
00074         }
00075         
00076         public function play():Void
00077         {
00078                 this.onEnterFrame = this.onEnterFrameHandler;
00079                 
00080                 super.play();
00081         }
00082          
00083         public function stop():Void
00084         {
00085                 interrupt();
00086         }
00087         
00088         public function isImmediatelyInterruptable() : Boolean
00089         {
00090                 return true;
00091         }
00092         
00093         public function interrupt() : Void
00094         {
00095                 mIsRunning = false;
00096                 
00097                 this.onEnterFrame = null;
00098                 super.stop();
00099                 
00100                 if(mHideAfterCompletion)
00101                 {
00102                         hide();
00103                 }
00104                 
00105                 dispatchEvent({type:"interrupted", target:this});
00106         }
00107         
00108         public function onEnterFrameHandler()
00109         {
00110                 if (!mIsRunning)
00111                 {
00112                         this.onEnterFrame = null;
00113                         return;
00114                 }
00115                 
00116                 for(var i:Number = mCuePoints.length - 1; i >= 0; i--)
00117                 {
00118                         if(this._currentframe >= mCuePoints[i].position)
00119                         {
00120                                 dispatchEvent({type:mCuePoints[i].event, target:this});
00121                                 break;
00122                         }
00123                 }
00124                 
00125                 if (!this.mDoLoop)
00126                 {
00127                         if(this._currentframe == this._totalframes)
00128                         {
00129                                 onAnimationCompleted();
00130                         }
00131                 }
00132         }
00133         
00137         private function dispatchCuePoint(aEvent : String) : Void
00138         {
00139                 dispatchEvent({type:aEvent, target:this});
00140         }
00141         
00142         private function onAnimationCompleted()
00143         {       
00144                 this.stop();    
00145                 
00146                 mIsRunning = false;
00147 
00148                 dispatchEvent({type:"completed", target:this});
00149 
00150                 if(mHideAfterCompletion)
00151                 {
00152                         hide(); 
00153                 }
00154         }
00155 }

Generated on Fri May 11 17:12:45 2007 for GuggaFramework by  doxygen 1.5.2