TweenListObj.as 11 KB

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