topical media & game development

talk show tell print

#graphic-flex-image-effects-07-source-aeon-animators-Scaler.ax

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


  package aeon.animators {
  
          import aeon.Animation;
          import aeon.easing.Linear;
          import aeon.events.AnimationEvent;
  
          
Tweens both width and height of an object.

  
          public class @ax-graphic-flex-image-effects-07-source-aeon-animators-Scaler extends Animation {
          
                  public static const PIXEL:String = "pixel";
                  public static const PERCENT:String = "percent";
          
                  private var _tween:Tweener;
                  private var _scaleType:String;
                  private var _target:Object;
                  private var _startValue:Object;
                  private var _endValue:Object;
                  private var _time:Number;
                  private var _easeFunction:Function;
          
                  
Constructor.
parameter: target The object on which the tween will perform.
parameter: startValue The value of the x and y properties at the start of the tween.
parameter: endValue The value of the x and y properties at the end of the tween.
parameter: time The number of milliseconds the tween should run.
parameter: scaleType Whether the scaling should be done by pixel value or by percent.
parameter: easeFunction The function to use to calculate values during the tween.

  
                  public function @ax-graphic-flex-image-effects-07-source-aeon-animators-Scaler(
                          target:Object,
                          startValue:Object,
                          endValue:Object,
                          time:Number,
                          scaleType:String=PIXEL,
                          easeFunction:Function=null
                  ) {
                          _target = target;
                          if (startValue is Number) {
                                  startValue = {x:startValue, y:startValue};
                                  endValue = {x:endValue, y:endValue};
                          }
                          _startValue = startValue;
                          _endValue = endValue;
                          _scaleType = scaleType;
                          _time = time;
                          if (easeFunction == null) easeFunction = Linear.easeNone;
                          _easeFunction = easeFunction;
                  }
          
                  
Called once the TweenRunner completes the tween.
parameter: event Event fired by TweenRunner.

  
                  private function onEndTween(event:AnimationEvent):void {
                          stop();
                          dispatchEvent(new AnimationEvent(AnimationEvent.END));
                  }
          
                  private function onChangeTween(event:AnimationEvent):void {
                          var changedValues:Object = _tween.currentValue;
                          if (_scaleType == PIXEL) {
                                  if (_target.hasOwnProperty("setSize")) {
                                          _target.setSize(changedValues.x, changedValues.y);
                                  } else {
                                          _target.width = changedValues.x;
                                          _target.height = changedValues.y;
                                  }
                          } else {
                                  _target.scaleX = changedValues.x;
                                  _target.scaleY = changedValues.y;
                          }
                          dispatchEvent(new AnimationEvent(AnimationEvent.CHANGE));
                  }
          
                  
Starts the animation.

  
                  override public function start():void {
                          _tween = new Tweener(null, _startValue, _endValue, _time, _easeFunction);
                          _tween.addEventListener(AnimationEvent.CHANGE, onChangeTween);
                          _tween.addEventListener(AnimationEvent.END, onEndTween);
                          _tween.start();
                          super.start();
                  }
          
                  
Stops the animation.

  
                  override public function stop():void {
                          super.stop();
                          _tween.removeEventListener(AnimationEvent.END, onEndTween);
                          _tween.stop();
                  }
          
          }
          
  }


(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.