topical media & game development

talk show tell print

#graphic-flex-image-effects-07-source-aeon-AnimationLoop.ax

#graphic-flex-image-effects-07-source-aeon-AnimationLoop.ax [swf] [flash] flex


  package aeon {
  
          import aeon.easing.Linear;
          import aeon.events.AnimationEvent;
  
          import flash.events.TimerEvent;
          import flash.utils.Timer;
  
          public class @ax-graphic-flex-image-effects-07-source-aeon-AnimationLoop extends Animation {
          
                  private var _animation:Animation;
                  private var _totalLoops:uint;
                  private var _currentLoop:uint;
  
                  public function @ax-graphic-flex-image-effects-07-source-aeon-AnimationLoop(
                          animation:Animation,
                          numLoops:Number=-1,
                          changeFunction:Function=null,
                          endFunction:Function=null
                  ) {
                          _animation = animation;
                          _animation.addEventListener(AnimationEvent.END, onEndAnimation);
                          _totalLoops = numLoops;
                          if (changeFunction != null) {
                                  _animation.addEventListener(AnimationEvent.CHANGE, changeFunction);
                          }
                          if (endFunction != null) {
                                  _animation.addEventListener(AnimationEvent.END, endFunction);
                          }
                  }
          
                  private function onEndAnimation(event:AnimationEvent):void {
                          if (_totalLoops > 0 && ++_currentLoop >= _totalLoops) {
                                  stop();
                                  dispatchEvent(new AnimationEvent(AnimationEvent.END));
                          } else {
                                  _animation.start();
                          }
                  }
  
                  override public function start():void {
                          _currentLoop = 0;
                          super.start();
                          _animation.start();
                  }
          
                  override public function stop():void {
                          super.stop();
                          if (_animation) {
                                  _animation.removeEventListener(AnimationEvent.END, onEndAnimation);
                                  _animation.stop();
                          }
                  }
  
                  public function get animation():Animation {
                          return _animation;
                  }
  
          }
  
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.