| 1 | package caurina.transitions {
|
|---|
| 2 | import caurina.transitions.AuxFunctions;
|
|---|
| 3 | /**
|
|---|
| 4 | * The tween list object. Stores all of the properties and information that pertain to individual tweens.
|
|---|
| 5 | *
|
|---|
| 6 | * @author Nate Chatellier, Zeh Fernando
|
|---|
| 7 | * @version 1.0.4
|
|---|
| 8 | * @private
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | public class TweenListObj {
|
|---|
| 12 |
|
|---|
| 13 | public var scope :Object; // Object affected by this tweening
|
|---|
| 14 | public var properties :Object; // List of properties that are tweened (PropertyInfoObj instances)
|
|---|
| 15 | // .valueStart :Number // Initial value of the property
|
|---|
| 16 | // .valueComplete :Number // The value the property should have when completed
|
|---|
| 17 | public var auxProperties :Object; // Dynamic object containing properties used on this tweening
|
|---|
| 18 | public var timeStart :Number; // Time when this tweening should start
|
|---|
| 19 | public var timeComplete :Number; // Time when this tweening should end
|
|---|
| 20 | public var useFrames :Boolean; // Whether or not to use frames instead of time
|
|---|
| 21 | public var transition :Function; // Equation to control the transition animation
|
|---|
| 22 | public var onStart :Function; // Function to be executed on the object when the tween starts (once)
|
|---|
| 23 | public var onUpdate :Function; // Function to be executed on the object when the tween updates (several times)
|
|---|
| 24 | public var onComplete :Function; // Function to be executed on the object when the tween completes (once)
|
|---|
| 25 | public var onOverwrite :Function; // Function to be executed on the object when the tween is overwritten
|
|---|
| 26 | public var onError :Function; // Function to be executed if an error is thrown when tweener exectues a callback (onComplete, onUpdate etc)
|
|---|
| 27 | public var onStartParams :Array; // Array of parameters to be passed for the event
|
|---|
| 28 | public var onUpdateParams :Array; // Array of parameters to be passed for the event
|
|---|
| 29 | public var onCompleteParams :Array; // Array of parameters to be passed for the event
|
|---|
| 30 | public var onOverwriteParams :Array; // Array of parameters to be passed for the event
|
|---|
| 31 | public var rounded :Boolean; // Use rounded values when updating
|
|---|
| 32 | public var isPaused :Boolean; // Whether or not this tween is paused
|
|---|
| 33 | public var timePaused :Number; // Time when this tween was paused
|
|---|
| 34 | public var isCaller :Boolean; // Whether or not this tween is a "caller" tween
|
|---|
| 35 | public var count :Number; // Number of times this caller should be called
|
|---|
| 36 | public var timesCalled :Number; // How many times the caller has already been called ("caller" tweens only)
|
|---|
| 37 | public var waitFrames :Boolean; // Whether or not this caller should wait at least one frame for each call execution ("caller" tweens only)
|
|---|
| 38 | public var skipUpdates :Number; // How many updates should be skipped (default = 0; 1 = update-skip-update-skip...)
|
|---|
| 39 | public var updatesSkipped :Number; // How many updates have already been skipped
|
|---|
| 40 | public var hasStarted :Boolean; // Whether or not this tween has already started
|
|---|
| 41 |
|
|---|
| 42 | // ==================================================================================================================================
|
|---|
| 43 | // CONSTRUCTOR function -------------------------------------------------------------------------------------------------------------
|
|---|
| 44 |
|
|---|
| 45 | /**
|
|---|
| 46 | * Initializes the basic TweenListObj.
|
|---|
| 47 | *
|
|---|
| 48 | * @param p_scope Object Object affected by this tweening
|
|---|
| 49 | * @param p_timeStart Number Time when this tweening should start
|
|---|
| 50 | * @param p_timeComplete Number Time when this tweening should end
|
|---|
| 51 | * @param p_useFrames Boolean Whether or not to use frames instead of time
|
|---|
| 52 | * @param p_transition Function Equation to control the transition animation
|
|---|
| 53 | */
|
|---|
| 54 | function TweenListObj(p_scope:Object, p_timeStart:Number, p_timeComplete:Number, p_useFrames:Boolean, p_transition:Function) {
|
|---|
| 55 | scope = p_scope;
|
|---|
| 56 | timeStart = p_timeStart;
|
|---|
| 57 | timeComplete = p_timeComplete;
|
|---|
| 58 | useFrames = p_useFrames;
|
|---|
| 59 | transition = p_transition;
|
|---|
| 60 |
|
|---|
| 61 | // Other default information
|
|---|
| 62 | auxProperties = new Object();
|
|---|
| 63 | properties = new Object();
|
|---|
| 64 | isPaused = false;
|
|---|
| 65 | timePaused = undefined;
|
|---|
| 66 | isCaller = false;
|
|---|
| 67 | updatesSkipped = 0;
|
|---|
| 68 | timesCalled = 0;
|
|---|
| 69 | skipUpdates = 0;
|
|---|
| 70 | hasStarted = false;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | // ==================================================================================================================================
|
|---|
| 75 | // OTHER functions ------------------------------------------------------------------------------------------------------------------
|
|---|
| 76 |
|
|---|
| 77 | /**
|
|---|
| 78 | * Clones this tweening and returns the new TweenListObj
|
|---|
| 79 | *
|
|---|
| 80 | * @param omitEvents Boolean Whether or not events such as onStart (and its parameters) should be omitted
|
|---|
| 81 | * @return TweenListObj A copy of this object
|
|---|
| 82 | */
|
|---|
| 83 | public function clone(omitEvents:Boolean):TweenListObj {
|
|---|
| 84 | var nTween:TweenListObj = new TweenListObj(scope, timeStart, timeComplete, useFrames, transition);
|
|---|
| 85 | nTween.properties = new Array();
|
|---|
| 86 | for (var pName:String in properties) {
|
|---|
| 87 | nTween.properties[pName] = properties[pName].clone();
|
|---|
| 88 | }
|
|---|
| 89 | nTween.skipUpdates = skipUpdates;
|
|---|
| 90 | nTween.updatesSkipped = updatesSkipped;
|
|---|
| 91 | if (!omitEvents) {
|
|---|
| 92 | nTween.onStart = onStart;
|
|---|
| 93 | nTween.onUpdate = onUpdate;
|
|---|
| 94 | nTween.onComplete = onComplete;
|
|---|
| 95 | nTween.onOverwrite = onOverwrite;
|
|---|
| 96 | nTween.onError = onError;
|
|---|
| 97 | nTween.onStartParams = onStartParams;
|
|---|
| 98 | nTween.onUpdateParams = onUpdateParams;
|
|---|
| 99 | nTween.onCompleteParams = onCompleteParams;
|
|---|
| 100 | nTween.onOverwriteParams = onOverwriteParams;
|
|---|
| 101 | }
|
|---|
| 102 | nTween.rounded = rounded;
|
|---|
| 103 | nTween.isPaused = isPaused;
|
|---|
| 104 | nTween.timePaused = timePaused;
|
|---|
| 105 | nTween.isCaller = isCaller;
|
|---|
| 106 | nTween.count = count;
|
|---|
| 107 | nTween.timesCalled = timesCalled;
|
|---|
| 108 | nTween.waitFrames = waitFrames;
|
|---|
| 109 | nTween.hasStarted = hasStarted;
|
|---|
| 110 |
|
|---|
| 111 | return nTween;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * Returns this object described as a String.
|
|---|
| 116 | *
|
|---|
| 117 | * @return String The description of this object.
|
|---|
| 118 | */
|
|---|
| 119 | public function toString():String {
|
|---|
| 120 | var returnStr:String = "\n[TweenListObj ";
|
|---|
| 121 | returnStr += "scope:" + String(scope);
|
|---|
| 122 | returnStr += ", properties:";
|
|---|
| 123 | for (var i:uint = 0; i < properties.length; i++) {
|
|---|
| 124 | if (i > 0) returnStr += ",";
|
|---|
| 125 | returnStr += "[name:"+properties[i].name;
|
|---|
| 126 | returnStr += ",valueStart:"+properties[i].valueStart;
|
|---|
| 127 | returnStr += ",valueComplete:"+properties[i].valueComplete;
|
|---|
| 128 | returnStr += "]";
|
|---|
| 129 | } // END FOR
|
|---|
| 130 | returnStr += ", timeStart:" + String(timeStart);
|
|---|
| 131 | returnStr += ", timeComplete:" + String(timeComplete);
|
|---|
| 132 | returnStr += ", useFrames:" + String(useFrames);
|
|---|
| 133 | returnStr += ", transition:" + String(transition);
|
|---|
| 134 |
|
|---|
| 135 | if (skipUpdates) returnStr += ", skipUpdates:" + String(skipUpdates);
|
|---|
| 136 | if (updatesSkipped) returnStr += ", updatesSkipped:" + String(updatesSkipped);
|
|---|
| 137 |
|
|---|
| 138 | if (Boolean(onStart)) returnStr += ", onStart:" + String(onStart);
|
|---|
| 139 | if (Boolean(onUpdate)) returnStr += ", onUpdate:" + String(onUpdate);
|
|---|
| 140 | if (Boolean(onComplete)) returnStr += ", onComplete:" + String(onComplete);
|
|---|
| 141 | if (Boolean(onOverwrite)) returnStr += ", onOverwrite:" + String(onOverwrite);
|
|---|
| 142 | if (Boolean(onError)) returnStr += ", onError:" + String(onError);
|
|---|
| 143 |
|
|---|
| 144 | if (onStartParams) returnStr += ", onStartParams:" + String(onStartParams);
|
|---|
| 145 | if (onUpdateParams) returnStr += ", onUpdateParams:" + String(onUpdateParams);
|
|---|
| 146 | if (onCompleteParams) returnStr += ", onCompleteParams:" + String(onCompleteParams);
|
|---|
| 147 | if (onOverwriteParams) returnStr += ", onOverwriteParams:" + String(onOverwriteParams);
|
|---|
| 148 |
|
|---|
| 149 | if (rounded) returnStr += ", rounded:" + String(rounded);
|
|---|
| 150 | if (isPaused) returnStr += ", isPaused:" + String(isPaused);
|
|---|
| 151 | if (timePaused) returnStr += ", timePaused:" + String(timePaused);
|
|---|
| 152 | if (isCaller) returnStr += ", isCaller:" + String(isCaller);
|
|---|
| 153 | if (count) returnStr += ", count:" + String(count);
|
|---|
| 154 | if (timesCalled) returnStr += ", timesCalled:" + String(timesCalled);
|
|---|
| 155 | if (waitFrames) returnStr += ", waitFrames:" + String(waitFrames);
|
|---|
| 156 | if (hasStarted) returnStr += ", hasStarted:" + String(hasStarted);
|
|---|
| 157 |
|
|---|
| 158 | returnStr += "]\n";
|
|---|
| 159 | return returnStr;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | /**
|
|---|
| 163 | * Checks if p_obj "inherits" properties from other objects, as set by the "base" property. Will create a new object, leaving others intact.
|
|---|
| 164 | * o_bj.base can be an object or an array of objects. Properties are collected from the first to the last element of the "base" filed, with higher
|
|---|
| 165 | * indexes overwritting smaller ones. Does not modify any of the passed objects, but makes a shallow copy of all properties.
|
|---|
| 166 | *
|
|---|
| 167 | * @param p_obj Object Object that should be tweened: a movieclip, textfield, etc.. OR an array of objects
|
|---|
| 168 | * @return Object A new object with all properties from the p_obj and p_obj.base.
|
|---|
| 169 | */
|
|---|
| 170 |
|
|---|
| 171 | public static function makePropertiesChain(p_obj : Object) : Object{
|
|---|
| 172 | // Is this object inheriting properties from another object?
|
|---|
| 173 | var baseObject : Object = p_obj.base;
|
|---|
| 174 | if(baseObject){
|
|---|
| 175 | // object inherits. Are we inheriting from an object or an array
|
|---|
| 176 | var chainedObject : Object = {};
|
|---|
| 177 | var chain : Object;
|
|---|
| 178 | if (baseObject is Array){
|
|---|
| 179 | // Inheritance chain is the base array
|
|---|
| 180 | chain = [];
|
|---|
| 181 | // make a shallow copy
|
|---|
| 182 | for (var k : Number = 0 ; k< baseObject.length; k++) chain.push(baseObject[k]);
|
|---|
| 183 | }else{
|
|---|
| 184 | // Only one object to be added to the array
|
|---|
| 185 | chain = [baseObject];
|
|---|
| 186 | }
|
|---|
| 187 | // add the final object to the array, so it's properties are added last
|
|---|
| 188 | chain.push(p_obj);
|
|---|
| 189 | var currChainObj : Object;
|
|---|
| 190 | // Loops through each object adding it's property to the final object
|
|---|
| 191 | var len : Number = chain.length;
|
|---|
| 192 | for(var i : Number = 0; i < len ; i ++){
|
|---|
| 193 | if(chain[i]["base"]){
|
|---|
| 194 | // deal with recursion: watch the order! "parent" base must be concatenated first!
|
|---|
| 195 | currChainObj = AuxFunctions.concatObjects( makePropertiesChain(chain[i]["base"] ), chain[i]);
|
|---|
| 196 | }else{
|
|---|
| 197 | currChainObj = chain[i] ;
|
|---|
| 198 | }
|
|---|
| 199 | chainedObject = AuxFunctions.concatObjects(chainedObject, currChainObj );
|
|---|
| 200 | }
|
|---|
| 201 | if( chainedObject["base"]){
|
|---|
| 202 | delete chainedObject["base"];
|
|---|
| 203 | }
|
|---|
| 204 | return chainedObject;
|
|---|
| 205 | }else{
|
|---|
| 206 | // No inheritance, just return the object it self
|
|---|
| 207 | return p_obj;
|
|---|
| 208 | }
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | }
|
|---|