00001 import gugga.events.EventDispatcher;
00002 import mx.utils.Delegate;
00003
00004 import flash.geom.ColorTransform;
00005
00006 import gugga.animations.AnimationSubjectCacheAsBitmapPolicy;
00007 import gugga.animations.IAnimation;
00008 import gugga.animations.PropertiesTweenAnimation;
00009 import gugga.common.EventDescriptor;
00010 import gugga.debug.Assertion;
00011 import gugga.tween.TweensManager;
00012 import gugga.utils.DebugUtils;
00013 import gugga.utils.EventRethrower;
00014 import gugga.utils.Listener;
00015
00019 class gugga.animations.ColorTransformTweenAnimation extends EventDispatcher implements IAnimation
00020 {
00021 private var mTweenAnimation : PropertiesTweenAnimation;
00022
00023 private var mMovieClip : MovieClip;
00024 private var mColorTransformObject : ColorTransform;
00025
00026 private var mTweeningProperties : Array = [
00027 "redMultiplier", "redOffset",
00028 "greenMultiplier", "greenOffset",
00029 "blueMultiplier", "blueOffset",
00030 "alphaMultiplier", "alphaOffset"
00031 ];
00032
00033 public function ColorTransformTweenAnimation ()
00034 {
00035 super();
00036
00037 mTweenAnimation = new PropertiesTweenAnimation();
00038
00039 mTweenAnimation.SubjectCacheAsBitmapPolicy =
00040 AnimationSubjectCacheAsBitmapPolicy.ForceFalseWhileAnimating;
00041
00042 mTweenAnimation.TweenUpdateDelegate = Delegate.create(this, onTweenUpdated);
00043
00044 mTweenAnimation.addEventListener("completed", Delegate.create(this, onTweenAnimationCompleted));
00045
00046 EventRethrower.create(this, mTweenAnimation, "start");
00047 EventRethrower.create(this, mTweenAnimation, "interrupted");
00048 }
00049
00050 private function getTweenToValues(aTransformationMatrix : Array) : Array
00051 {
00052 var tweenToValues : Array = new Array();
00053 tweenToValues[0] = aTransformationMatrix[0] / 100;
00054 tweenToValues[1] = aTransformationMatrix[1];
00055 tweenToValues[2] = aTransformationMatrix[2] / 100;
00056 tweenToValues[3] = aTransformationMatrix[3];
00057 tweenToValues[4] = aTransformationMatrix[4] / 100;
00058 tweenToValues[5] = aTransformationMatrix[5];
00059 tweenToValues[6] = aTransformationMatrix[6] / 100;
00060 tweenToValues[7] = aTransformationMatrix[7];
00061
00062 return tweenToValues;
00063 }
00064
00065 public function setTimeTween(
00066 aMovieClip : MovieClip,
00067 aTransformationMatrix : Array,
00068 aTweenTime : Number,
00069 aEasingEquation : Function) : Void
00070 {
00071 Assertion.failIfNull(aMovieClip, "ColorTransformation subject is empty !", this, arguments);
00072
00073 mMovieClip = aMovieClip;
00074
00075 var tweenToValues : Array = getTweenToValues(aTransformationMatrix);
00076
00077 mTweenAnimation.setTimeTween(
00078 new Object(),
00079 mTweeningProperties,
00080 tweenToValues,
00081 aTweenTime,
00082 aEasingEquation);
00083 }
00084
00085 public function setFrameTween(
00086 aMovieClip : MovieClip,
00087 aTransformationMatrix : Array,
00088 aTweenTime : Number,
00089 aEasingEquation : Function) : Void
00090 {
00091 Assertion.failIfNull(aMovieClip, "ColorTransformation subject is empty !", this, arguments);
00092
00093 mMovieClip = aMovieClip;
00094
00095 var tweenToValues : Array = getTweenToValues(aTransformationMatrix);
00096
00097 mTweenAnimation.setFrameTween(
00098 new Object(),
00099 mTweeningProperties,
00100 tweenToValues,
00101 aTweenTime,
00102 aEasingEquation);
00103 }
00104
00105 private function onTweenUpdated()
00106 {
00107 mMovieClip.transform.colorTransform = mColorTransformObject;
00108 }
00109
00110 private function onTweenAnimationCompleted()
00111 {
00112 dispatchEvent({type: "completed", target: this});
00113 }
00114
00115 public function start() : Void
00116 {
00117 mColorTransformObject = mMovieClip.transform.colorTransform;
00118 mTweenAnimation.Subject = mColorTransformObject;
00119
00120 mTweenAnimation.start();
00121 }
00122
00123 public function interrupt() : Void
00124 {
00125 mTweenAnimation.interrupt();
00126 }
00127
00128 public function addCuePoint(aPosition : Number, aEventName : String) : Void
00129 {
00130 mTweenAnimation.addCuePoint(aPosition, aEventName);
00131 EventRethrower.create(this, mTweenAnimation, aEventName);
00132 }
00133
00134 public function isRunning() : Boolean
00135 {
00136 return mTweenAnimation.isRunning();
00137 }
00138
00139 public function isImmediatelyInterruptable() : Boolean
00140 {
00141 return mTweenAnimation.isImmediatelyInterruptable();
00142 }
00143 }