TweenMax.as 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. /**
  2. * VERSION: 11.37
  3. * DATE: 2010-05-14
  4. * AS3 (AS2 version is also available)
  5. * UPDATES AND DOCUMENTATION AT: http://www.TweenMax.com
  6. **/
  7. package com.greensock {
  8. import com.greensock.core.*;
  9. import com.greensock.events.TweenEvent;
  10. import com.greensock.plugins.*;
  11. import flash.display.*;
  12. import flash.events.*;
  13. import flash.utils.*;
  14. /**
  15. * TweenMax extends the extremely lightweight, fast TweenLite engine, adding many useful features
  16. * like timeScale, event dispatching, updateTo(), yoyo, repeat, repeatDelay, rounding, and more. It also
  17. * activates many extra plugins by default, making it extremely full-featured. Since TweenMax extends
  18. * TweenLite, it can do ANYTHING TweenLite can do plus much more. The syntax is identical. With plenty
  19. * of other tweening engines to choose from, here's why you might want to consider TweenMax:
  20. *
  21. * <ul>
  22. * <li><b> SPEED </b>- TweenMax has been highly optimized for maximum performance. See some speed comparisons yourself at
  23. * <a href="http://www.greensock.com/tweening-speed-test/">http://www.greensock.com/tweening-speed-test/</a></li>
  24. *
  25. * <li><b> Feature set </b>- In addition to tweening ANY numeric property of ANY object, TweenMax can tween filters,
  26. * hex colors, volume, tint, frames, saturation, contrast, hue, colorization, brightness, and even do
  27. * bezier tweening, orientToBezier, round values, jump to any point in the tween with the <code>currentTime</code>
  28. * or <code>currentProgress</code> property, automatically rotate in the shortest direction, plus LOTS more.
  29. * Overwrite management is an important consideration for a tweening engine as well which is another area
  30. * where the GreenSock Tweening Platform shines. You have options for AUTO overwriting or you can manually
  31. * define how each tween will handle overlapping tweens of the same object.</li>
  32. *
  33. * <li><b> Expandability </b>- With its plugin architecture, you can activate as many (or as few) features as your
  34. * project requires. Write your own plugin to handle particular special properties in custom ways. Minimize bloat, and
  35. * maximize performance.</li>
  36. *
  37. * <li><b> Sequencing, grouping, and management features </b>- TimelineLite and TimelineMax make it surprisingly
  38. * simple to create complex sequences or groups of tweens that you can control as a whole. play(), pause(), restart(),
  39. * or reverse(). You can even tween a timeline's <code>currentTime</code> or <code>currentProgress</code> property
  40. * to fastforward or rewind the entire timeline. Add labels, gotoAndPlay(), change the timeline's timeScale, nest
  41. * timelines within timelines, and lots more.</li>
  42. *
  43. * <li><b> Ease of use </b>- Designers and Developers alike rave about how intuitive the platform is.</li>
  44. *
  45. * <li><b> Updates </b>- Frequent updates and feature additions make the GreenSock Tweening Platform reliable and robust.</li>
  46. *
  47. * <li><b> AS2 and AS3 </b>- Most other engines are only developed for AS2 or AS3 but not both.</li>
  48. * </ul>
  49. *
  50. * <b>SPECIAL PROPERTIES (no plugins required):</b><br /><br />
  51. *
  52. * Any of the following special properties can optionally be passed in through the vars object (the third parameter):
  53. * <ul>
  54. * <li><b> delay : Number</b> Amount of delay in seconds (or frames for frames-based tweens) before the tween should begin.</li>
  55. *
  56. * <li><b> useFrames : Boolean</b> If useFrames is set to true, the tweens's timing mode will be based on frames.
  57. * Otherwise, it will be based on seconds/time. NOTE: a tween's timing mode is
  58. * always determined by its parent timeline. </li>
  59. *
  60. * <li><b> ease : Function</b> Use any standard easing equation to control the rate of change. For example,
  61. * Elastic.easeOut. The Default is Quad.easeOut.</li>
  62. *
  63. * <li><b> easeParams : Array</b> An Array of extra parameters to feed the easing equation (beyond the standard first 4).
  64. * This can be useful when using an ease like Elastic and want to control extra parameters
  65. * like the amplitude and period. Most easing equations, however, don't require extra parameters
  66. * so you won't need to pass in any easeParams.</li>
  67. *
  68. * <li><b> onInit : Function</b> A function that should be called just before the tween inits (renders for the first time).
  69. * Since onInit runs before the start/end values are recorded internally, it is a good place to run
  70. * code that affects the target's initial position or other tween-related properties. onStart, by
  71. * contrast, runs AFTER the tween inits and the start/end values are recorded internally. onStart
  72. * is called every time the tween begins which can happen more than once if the tween is restarted
  73. * multiple times.</li>
  74. *
  75. * <li><b> onInitParams : Array</b> An Array of parameters to pass the onInit function.</li>
  76. *
  77. * <li><b> onStart : Function</b> A function that should be called when the tween begins (when its currentTime is at 0 and
  78. * changes to some other value which can happen more than once if the tween is restarted multiple times).</li>
  79. *
  80. * <li><b> onStartParams : Array</b> An Array of parameters to pass the onStart function.</li>
  81. *
  82. * <li><b> onUpdate : Function</b> A function that should be called every time the tween's time/position is updated
  83. * (on every frame while the timeline is active)</li>
  84. *
  85. * <li><b> onUpdateParams : Array</b> An Array of parameters to pass the onUpdate function</li>
  86. *
  87. * <li><b> onComplete : Function</b> A function that should be called when the tween has finished </li>
  88. *
  89. * <li><b> onCompleteParams : Array</b> An Array of parameters to pass the onComplete function</li>
  90. *
  91. * <li><b> onReverseComplete : Function</b> A function that should be called when the tween has reached its starting point again after having been reversed. </li>
  92. *
  93. * <li><b> onReverseCompleteParams : Array</b> An Array of parameters to pass the onReverseComplete function.</li>
  94. *
  95. * <li><b> onRepeat : Function</b> A function that should be called every time the tween repeats </li>
  96. *
  97. * <li><b> onRepeatParams : Array</b> An Array of parameters to pass the onRepeat function</li>
  98. *
  99. * <li><b> immediateRender : Boolean</b> Normally when you create a tween, it begins rendering on the very next frame (when
  100. * the Flash Player dispatches an ENTER_FRAME event) unless you specify a <code>delay</code>. This
  101. * allows you to insert tweens into timelines and perform other actions that may affect
  102. * its timing. However, if you prefer to force the tween to render immediately when it is
  103. * created, set <code>immediateRender</code> to true. Or to prevent a tween with a duration of zero from
  104. * rendering immediately, set this to false.</li>
  105. *
  106. * <li><b> paused : Boolean</b> If true, the tween will be paused initially.</li>
  107. *
  108. * <li><b> reversed : Boolean</b> If true, the tween will be reversed initially. This does not swap the starting/ending
  109. * values in the tween - it literally changes its orientation/direction. Imagine the playhead
  110. * moving backwards instead of forwards. This does NOT force it to the very end and start
  111. * playing backwards. It simply affects the orientation of the tween, so if reversed is set to
  112. * true initially, it will appear not to play because it is already at the beginning. To cause it to
  113. * play backwards from the end, set reversed to true and then set the <code>currentProgress</code>
  114. * property to 1 immediately after creating the tween (or set the currentTime to the duration). </li>
  115. *
  116. * <li><b> overwrite : int</b> Controls how (and if) other tweens of the same target are overwritten by this tween. There are
  117. * several modes to choose from, and TweenMax automatically calls <code>OverwriteManager.init()</code> if you haven't
  118. * already manually dones so, which means that by default <code>AUTO</code> mode is used (please see
  119. * <a href="http://www.greensock.com/overwritemanager/">http://www.greensock.com/overwritemanager/</a>
  120. * for details and a full explanation of the various modes):
  121. * <ul>
  122. * <li>NONE (0) (or false) </li>
  123. *
  124. * <li>ALL_IMMEDIATE (1) (or true)</li>
  125. *
  126. * <li>AUTO (2) - this is the default mode for TweenMax.</li>
  127. *
  128. * <li>CONCURRENT (3)</li>
  129. *
  130. * <li>ALL_ONSTART (4)</li>
  131. *
  132. * <li>PREEXISTING (5)</li>
  133. *
  134. * </ul></li>
  135. *
  136. * <li><b> repeat : int</b> Number of times that the tween should repeat. To repeat indefinitely, use -1.</li>
  137. *
  138. * <li><b> repeatDelay : Number</b> Amount of time in seconds (or frames for frames-based tween) between repeats.</li>
  139. *
  140. * <li><b> yoyo : Boolean</b> Works in conjunction with the repeat property, determining the behavior of each
  141. * cycle. When yoyo is true, the tween will go back and forth, appearing to reverse
  142. * every other cycle (this has no affect on the "reversed" property though). So if repeat is
  143. * 2 and yoyo is false, it will look like: start - 1 - 2 - 3 - 1 - 2 - 3 - 1 - 2 - 3 - end. But
  144. * if repeat is 2 and yoyo is true, it will look like: start - 1 - 2 - 3 - 3 - 2 - 1 - 1 - 2 - 3 - end. </li>
  145. *
  146. * <li><b> onStartListener : Function</b> A function to which the TweenMax instance should dispatch a TweenEvent when it begins.
  147. * This is the same as doing <code>myTween.addEventListener(TweenEvent.START, myFunction);</code></li>
  148. *
  149. * <li><b> onUpdateListener : Function</b> A function to which the TweenMax instance should dispatch a TweenEvent every time it
  150. * updates values. This is the same as doing <code>myTween.addEventListener(TweenEvent.UPDATE, myFunction);</code></li>
  151. *
  152. * <li><b> onCompleteListener : Function</b> A function to which the TweenMax instance should dispatch a TweenEvent when it completes.
  153. * This is the same as doing <code>myTween.addEventListener(TweenEvent.COMPLETE, myFunction);</code></li>
  154. *
  155. * <li><b> onReverseCompleteListener : Function</b> A function to which the TweenMax instance should dispatch a TweenEvent when it completes
  156. * in the reverse direction. This is the same as doing <code>myTween.addEventListener(TweenEvent.REVERSE_COMPLETE, myFunction);</code></li>
  157. *
  158. * <li><b> onRepeatListener : Function</b> A function to which the TweenMax instance should dispatch a TweenEvent when it repeats.
  159. * This is the same as doing <code>myTween.addEventListener(TweenEvent.REPEAT, myFunction);</code></li>
  160. *
  161. * <li><b> startAt : Object</b> Allows you to define the starting values for each property. Typically, TweenMax uses the current
  162. * value (whatever it happens to be at the time the tween begins) as the start value, but startAt
  163. * allows you to override that behavior. Simply pass an object in with whatever properties you'd like
  164. * to set just before the tween begins. For example, if mc.x is currently 100, and you'd like to
  165. * tween it from 0 to 500, do <code>TweenMax.to(mc, 2, {x:500, startAt:{x:0}});</code> </li>
  166. * </ul>
  167. *
  168. * <b>PLUGINS: </b><br /><br />
  169. *
  170. * There are many plugins that add capabilities through other special properties. Adding the capabilities
  171. * is as simple as activating the plugin with a single line of code, like <code>TweenPlugin.activate([SetSizePlugin]);</code>
  172. * Get information about all the plugins at <a href="http://www.TweenMax.com">http://www.TweenMax.com</a>. The
  173. * following plugins are activated by default in TweenMax (you can easily prevent them from activating, thus
  174. * saving file size, by commenting out the associated activation lines towards the top of the class):
  175. *
  176. * <ul>
  177. * <li><b> autoAlpha : Number</b> - Use it instead of the alpha property to gain the additional feature of toggling
  178. * the visible property to false when alpha reaches 0. It will also toggle visible
  179. * to true before the tween starts if the value of autoAlpha is greater than zero.</li>
  180. *
  181. * <li><b> visible : Boolean</b> - To set a DisplayObject's "visible" property at the end of the tween, use this special property.</li>
  182. *
  183. * <li><b> volume : Number</b> - Tweens the volume of an object with a soundTransform property (MovieClip/SoundChannel/NetStream, etc.)</li>
  184. *
  185. * <li><b> tint : Number</b> - To change a DisplayObject's tint/color, set this to the hex value of the tint you'd like
  186. * to end up at(or begin at if you're using TweenMax.from()). An example hex value would be 0xFF0000.</li>
  187. *
  188. * <li><b> removeTint : Boolean</b> - If you'd like to remove the tint that's applied to a DisplayObject, pass true for this special property.</li>
  189. *
  190. * <li><b> frame : Number</b> - Use this to tween a MovieClip to a particular frame.</li>
  191. *
  192. * <li><b> bezier : Array</b> - Bezier tweening allows you to tween in a non-linear way. For example, you may want to tween
  193. * a MovieClip's position from the origin (0,0) 500 pixels to the right (500,0) but curve downwards
  194. * through the middle of the tween. Simply pass as many objects in the bezier array as you'd like,
  195. * one for each "control point" (see documentation on Flash's curveTo() drawing method for more
  196. * about how control points work). In this example, let's say the control point would be at x/y coordinates
  197. * 250,50. Just make sure your my_mc is at coordinates 0,0 and then do:
  198. * <code>TweenMax.to(my_mc, 3, {bezier:[{x:250, y:50}, {x:500, y:0}]});</code></li>
  199. *
  200. * <li><b> bezierThrough : Array</b> - Identical to bezier except that instead of passing bezier control point values, you
  201. * pass points through which the bezier values should move. This can be more intuitive
  202. * than using control points.</li>
  203. *
  204. * <li><b> orientToBezier : Array (or Boolean)</b> - A common effect that designers/developers want is for a MovieClip/Sprite to
  205. * orient itself in the direction of a Bezier path (alter its rotation). orientToBezier
  206. * makes it easy. In order to alter a rotation property accurately, TweenMax needs 4 pieces
  207. * of information:
  208. * <ol>
  209. * <li> Position property 1 (typically "x")</li>
  210. * <li> Position property 2 (typically "y")</li>
  211. * <li> Rotational property (typically "rotation")</li>
  212. * <li> Number of degrees to add (optional - makes it easy to orient your MovieClip properly)</li>
  213. * </ol>
  214. * The orientToBezier property should be an Array containing one Array for each set of these values.
  215. * For maximum flexibility, you can pass in any number of arrays inside the container array, one
  216. * for each rotational property. This can be convenient when working in 3D because you can rotate
  217. * on multiple axis. If you're doing a standard 2D x/y tween on a bezier, you can simply pass
  218. * in a boolean value of true and TweenMax will use a typical setup, <code>[["x", "y", "rotation", 0]]</code>.
  219. * Hint: Don't forget the container Array (notice the double outer brackets)</li>
  220. *
  221. * <li><b> hexColors : Object</b> - Although hex colors are technically numbers, if you try to tween them conventionally,
  222. * you'll notice that they don't tween smoothly. To tween them properly, the red, green, and
  223. * blue components must be extracted and tweened independently. TweenMax makes it easy. To tween
  224. * a property of your object that's a hex color to another hex color, use this special hexColors
  225. * property of TweenMax. It must be an OBJECT with properties named the same as your object's
  226. * hex color properties. For example, if your my_obj object has a "myHexColor" property that you'd like
  227. * to tween to red (0xFF0000) over the course of 2 seconds, do: <br />
  228. * <code>TweenMax.to(my_obj, 2, {hexColors:{myHexColor:0xFF0000}});</code><br />
  229. * You can pass in any number of hexColor properties.</li>
  230. *
  231. * <li><b> shortRotation : Object</b> - To tween the rotation property of the target object in the shortest direction, use "shortRotation"
  232. * instead of "rotation" as the property. For example, if <code>myObject.rotation</code> is currently 170 degrees
  233. * and you want to tween it to -170 degrees, a normal rotation tween would travel a total of 340 degrees
  234. * in the counter-clockwise direction, but if you use shortRotation, it would travel 20 degrees in the
  235. * clockwise direction instead.</li>
  236. *
  237. * <li><b> roundProps : Array</b> - If you'd like the inbetween values in a tween to always get rounded to the nearest integer, use the roundProps
  238. * special property. Just pass in an Array containing the property names that you'd like rounded. For example,
  239. * if you're tweening the x, y, and alpha properties of mc and you want to round the x and y values (not alpha)
  240. * every time the tween is rendered, you'd do: <code>TweenMax.to(mc, 2, {x:300, y:200, alpha:0.5, roundProps:["x","y"]});</code></li>
  241. *
  242. * <li><b> blurFilter : Object</b> - To apply a BlurFilter, pass an object with one or more of the following properties:
  243. * <code>blurX, blurY, quality, remove, addFilter, index</code></li>
  244. *
  245. * <li><b> glowFilter : Object</b> - To apply a GlowFilter, pass an object with one or more of the following properties:
  246. * <code>alpha, blurX, blurY, color, strength, quality, inner, knockout, remove, addFilter, index</code></li>
  247. *
  248. * <li><b> colorMatrixFilter : Object</b> - To apply a ColorMatrixFilter, pass an object with one or more of the following properties:
  249. * <code>colorize, amount, contrast, brightness, saturation, hue, threshold, relative, matrix, remove, addFilter, index</code></li>
  250. *
  251. * <li><b> dropShadowFilter : Object</b> - To apply a DropShadowFilter, pass an object with one or more of the following properties:
  252. * <code>alpha, angle, blurX, blurY, color, distance, strength, quality, remove, addFilter, index</code></li>
  253. *
  254. * <li><b> bevelFilter : Object</b> - To apply a BevelFilter, pass an object with one or more of the following properties:
  255. * <code>angle, blurX, blurY, distance, highlightAlpha, highlightColor, shadowAlpha, shadowColor, strength, quality, remove, addFilter, index</code></li>
  256. * </ul>
  257. *
  258. *
  259. * <b>EXAMPLES:</b><br /><br />
  260. *
  261. * Please see <a href="http://www.tweenmax.com">http://www.tweenmax.com</a> for examples, tutorials, and interactive demos. <br /><br />
  262. *
  263. * <b>NOTES / TIPS:</b>
  264. * <ul>
  265. * <li> Passing values as Strings will make the tween relative to the current value. For example, if you do
  266. * <code>TweenMax.to(mc, 2, {x:"-20"});</code> it'll move the mc.x to the left 20 pixels which is the same as doing
  267. * <code>TweenMax.to(mc, 2, {x:mc.x - 20});</code> You could also cast it like: <code>TweenMax.to(mc, 2, {x:String(myVariable)});</code></li>
  268. *
  269. * <li> If you prefer, instead of using the onCompleteListener, onInitListener, onStartListener, and onUpdateListener special properties,
  270. * you can set up listeners the typical way, like:<br /><code>
  271. * var myTween:TweenMax = new TweenMax(my_mc, 2, {x:200});<br />
  272. * myTween.addEventListener(TweenEvent.COMPLETE, myFunction);</code></li>
  273. *
  274. * <li> You can kill all tweens of a particular object anytime with the <code>TweenMax.killTweensOf(myObject); </code></li>
  275. *
  276. * <li> You can kill all delayedCalls to a particular function using <code>TweenMax.killDelayedCallsTo(myFunction);</code>
  277. * This can be helpful if you want to preempt a call.</li>
  278. *
  279. * <li> Use the <code>TweenMax.from()</code> method to animate things into place. For example, if you have things set up on
  280. * the stage in the spot where they should end up, and you just want to animate them into place, you can
  281. * pass in the beginning x and/or y and/or alpha (or whatever properties you want).</li>
  282. *
  283. * <li> If you find this class useful, please consider joining Club GreenSock which not only helps to sustain
  284. * ongoing development, but also gets you bonus plugins, classes and other benefits that are ONLY available
  285. * to members. Learn more at <a href="http://www.greensock.com/club/">http://www.greensock.com/club/</a></li>
  286. * </ul>
  287. *
  288. * <b>Copyright 2010, GreenSock. All rights reserved.</b> This work is subject to the terms in <a href="http://www.greensock.com/terms_of_use.html">http://www.greensock.com/terms_of_use.html</a> or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
  289. *
  290. * @author Jack Doyle, jack@greensock.com
  291. */
  292. public class TweenMax extends TweenLite implements IEventDispatcher {
  293. /** @private **/
  294. public static const version:Number = 11.37;
  295. TweenPlugin.activate([
  296. //ACTIVATE (OR DEACTIVATE) PLUGINS HERE...
  297. AutoAlphaPlugin, //tweens alpha and then toggles "visible" to false if/when alpha is zero
  298. EndArrayPlugin, //tweens numbers in an Array
  299. FramePlugin, //tweens MovieClip frames
  300. RemoveTintPlugin, //allows you to remove a tint
  301. TintPlugin, //tweens tints
  302. VisiblePlugin, //tweens a target's "visible" property
  303. VolumePlugin, //tweens the volume of a MovieClip or SoundChannel or anything with a "soundTransform" property
  304. BevelFilterPlugin, //tweens BevelFilters
  305. BezierPlugin, //enables bezier tweening
  306. BezierThroughPlugin, //enables bezierThrough tweening
  307. BlurFilterPlugin, //tweens BlurFilters
  308. ColorMatrixFilterPlugin, //tweens ColorMatrixFilters (including hue, saturation, colorize, contrast, brightness, and threshold)
  309. ColorTransformPlugin, //tweens advanced color properties like exposure, brightness, tintAmount, redOffset, redMultiplier, etc.
  310. DropShadowFilterPlugin, //tweens DropShadowFilters
  311. FrameLabelPlugin, //tweens a MovieClip to particular label
  312. GlowFilterPlugin, //tweens GlowFilters
  313. HexColorsPlugin, //tweens hex colors
  314. RoundPropsPlugin, //enables the roundProps special property for rounding values (ONLY for TweenMax!)
  315. ShortRotationPlugin, //tweens rotation values in the shortest direction
  316. //QuaternionsPlugin, //tweens 3D Quaternions
  317. //ScalePlugin, //Tweens both the _xscale and _yscale properties
  318. //ScrollRectPlugin, //tweens the scrollRect property of a DisplayObject
  319. //SetSizePlugin, //tweens the width/height of components via setSize()
  320. //SetActualSizePlugin, //tweens the width/height of components via setActualSize()
  321. //TransformMatrixPlugin, //Tweens the transform.matrix property of any DisplayObject
  322. //DynamicPropsPlugin, //tweens to dynamic end values. You associate the property with a particular function that returns the target end value **Club GreenSock membership benefit**
  323. //MotionBlurPlugin, //applies a directional blur to a DisplayObject based on the velocity and angle of movement. **Club GreenSock membership benefit**
  324. //Physics2DPlugin, //allows you to apply basic physics in 2D space, like velocity, angle, gravity, friction, acceleration, and accelerationAngle. **Club GreenSock membership benefit**
  325. //PhysicsPropsPlugin, //allows you to apply basic physics to any property using forces like velocity, acceleration, and/or friction. **Club GreenSock membership benefit**
  326. //TransformAroundCenterPlugin,//tweens the scale and/or rotation of DisplayObjects using the DisplayObject's center as the registration point **Club GreenSock membership benefit**
  327. //TransformAroundPointPlugin, //tweens the scale and/or rotation of DisplayObjects around a particular point (like a custom registration point) **Club GreenSock membership benefit**
  328. {}]); //activated in static var instead of constructor because otherwise if there's a from() tween, TweenLite's constructor would get called first and initTweenVals() would run before the plugins were activated.
  329. /** @private Just to make sure OverwriteManager is activated. **/
  330. private static var _overwriteMode:int = (OverwriteManager.enabled) ? OverwriteManager.mode : OverwriteManager.init(2);
  331. /**
  332. * Kills all the tweens of a particular object, optionally completing them first.
  333. *
  334. * @param target Object whose tweens should be immediately killed
  335. * @param complete Indicates whether or not the tweens should be forced to completion before being killed.
  336. */
  337. public static var killTweensOf:Function = TweenLite.killTweensOf;
  338. /** @private **/
  339. public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
  340. /** @private **/
  341. protected var _dispatcher:EventDispatcher;
  342. /** @private **/
  343. protected var _hasUpdateListener:Boolean;
  344. /** @private **/
  345. protected var _repeat:int = 0;
  346. /** @private **/
  347. protected var _repeatDelay:Number = 0;
  348. /** @private **/
  349. protected var _cyclesComplete:uint = 0;
  350. /** @private Indicates the strength of the fast ease - only used for eases that are optimized to make use of the internal code in the render() loop (ones that are activated with FastEase.activate()) **/
  351. protected var _easePower:uint;
  352. /** @private 0 = standard function, 1 = optimized easeIn, 2 = optimized easeOut, 3 = optimized easeInOut. Only used for eases that are optimized to make use of the internal code in the render() loop (ones that are activated with FastEase.activate()) **/
  353. protected var _easeType:uint;
  354. /**
  355. * Works in conjunction with the repeat property, determining the behavior of each cycle; when yoyo is true,
  356. * the tween will go back and forth, appearing to reverse every other cycle (this has no affect on the "reversed"
  357. * property though). So if repeat is 2 and yoyo is false, it will look like: start - 1 - 2 - 3 - 1 - 2 - 3 - 1 - 2 - 3 - end.
  358. * But if repeat is 2 and yoyo is true, it will look like: start - 1 - 2 - 3 - 3 - 2 - 1 - 1 - 2 - 3 - end.
  359. **/
  360. public var yoyo:Boolean;
  361. /**
  362. * Constructor
  363. *
  364. * @param target Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
  365. * @param duration Duration in seconds (or in frames if the tween's timing mode is frames-based)
  366. * @param vars An object containing the end values of the properties you're tweening. For example, to tween to x=100, y=100, you could pass {x:100, y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
  367. */
  368. public function TweenMax(target:Object, duration:Number, vars:Object) {
  369. super(target, duration, vars);
  370. if (TweenLite.version < 11.2) {
  371. throw new Error("TweenMax error! Please update your TweenLite class or try deleting your ASO files. TweenMax requires a more recent version. Download updates at http://www.TweenMax.com.");
  372. }
  373. this.yoyo = Boolean(this.vars.yoyo);
  374. _repeat = (this.vars.repeat) ? int(this.vars.repeat) : 0;
  375. _repeatDelay = (this.vars.repeatDelay) ? Number(this.vars.repeatDelay) : 0;
  376. this.cacheIsDirty = true; //ensures that if there is any repeat, the totalDuration will get recalculated to accurately report it.
  377. if (this.vars.onCompleteListener || this.vars.onInitListener || this.vars.onUpdateListener || this.vars.onStartListener || this.vars.onRepeatListener || this.vars.onReverseCompleteListener) {
  378. initDispatcher();
  379. if (duration == 0 && _delay == 0) {
  380. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.UPDATE));
  381. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.COMPLETE));
  382. }
  383. }
  384. if (this.vars.timeScale && !(this.target is TweenCore)) {
  385. this.cachedTimeScale = this.vars.timeScale;
  386. }
  387. }
  388. /**
  389. * @private
  390. * Initializes the property tweens, determining their start values and amount of change.
  391. * Also triggers overwriting if necessary and sets the _hasUpdate variable.
  392. */
  393. override protected function init():void {
  394. if (this.vars.startAt) {
  395. this.vars.startAt.overwrite = 0;
  396. this.vars.startAt.immediateRender = true;
  397. var startTween:TweenMax = new TweenMax(this.target, 0, this.vars.startAt);
  398. }
  399. if (_dispatcher) {
  400. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.INIT));
  401. }
  402. super.init();
  403. if (_ease in fastEaseLookup) {
  404. _easeType = fastEaseLookup[_ease][0];
  405. _easePower = fastEaseLookup[_ease][1];
  406. }
  407. //accommodate rounding if necessary...
  408. if (this.vars.roundProps != null && "roundProps" in TweenLite.plugins) {
  409. var j:int, prop:String, multiProps:String, rp:Array = this.vars.roundProps, plugin:Object, ptPlugin:PropTween, pt:PropTween;
  410. var i:int = rp.length;
  411. while (--i > -1) {
  412. prop = rp[i];
  413. pt = this.cachedPT1;
  414. while (pt) {
  415. if (pt.name == prop) {
  416. if (pt.isPlugin) {
  417. pt.target.round = true;
  418. } else {
  419. if (plugin == null) {
  420. plugin = new TweenLite.plugins.roundProps();
  421. plugin.add(pt.target, prop, pt.start, pt.change);
  422. _hasPlugins = true;
  423. this.cachedPT1 = ptPlugin = insertPropTween(plugin, "changeFactor", 0, 1, "_MULTIPLE_", true, this.cachedPT1);
  424. } else {
  425. plugin.add(pt.target, prop, pt.start, pt.change); //using a single plugin for rounding speeds processing
  426. }
  427. this.removePropTween(pt);
  428. this.propTweenLookup[prop] = ptPlugin;
  429. }
  430. } else if (pt.isPlugin && pt.name == "_MULTIPLE_" && !pt.target.round) {
  431. multiProps = " " + pt.target.overwriteProps.join(" ") + " ";
  432. if (multiProps.indexOf(" " + prop + " ") != -1) {
  433. pt.target.round = true;
  434. }
  435. }
  436. pt = pt.nextNode;
  437. }
  438. }
  439. }
  440. }
  441. /**
  442. * @private
  443. * Inserts a new property tween into the linked list.
  444. *
  445. * @param target Object whose property is being tweened
  446. * @param property Name of the property that is being tweened (according to the property tween's target)
  447. * @param start Starting value of the property
  448. * @param end End value of the property (if it is a String, it will be interpreted as relative)
  449. * @param name The name of the property that is being tweened (according to tween's target). This can be different than the "property". For example, for a bezier tween, the target could be the plugin, the property could be "changeFactor", and the name could be "x" or "_MULTIPLE_" if the plugin is managing more than one property. This aids in overwrite management.
  450. * @param isPlugin Indicates whether or not the property tween is a plugin
  451. * @param nextNode Next PropTween instance in the linked list. (this just helps speed things up)
  452. * @return PropTween instance that was created/inserted
  453. */
  454. protected function insertPropTween(target:Object, property:String, start:Number, end:*, name:String, isPlugin:Boolean, nextNode:PropTween):PropTween {
  455. var pt:PropTween = new PropTween(target, property, start, (typeof(end) == "number") ? end - start : Number(end), name, isPlugin, nextNode);
  456. if (isPlugin && name == "_MULTIPLE_") {
  457. var op:Array = target.overwriteProps;
  458. var i:int = op.length;
  459. while (--i > -1) {
  460. this.propTweenLookup[op[i]] = pt;
  461. }
  462. } else {
  463. this.propTweenLookup[name] = pt;
  464. }
  465. return pt;
  466. }
  467. /**
  468. * @private
  469. * Removes a PropTween from the linked list
  470. *
  471. * @param propTween PropTween to remove
  472. * @return Boolean value indicating whether or not properties may have changed on the target when the PropTween was disabled. For example, when a motionBlur (plugin) is disabled, it swaps out a BitmapData for the target and may alter the alpha. We need to know this in order to determine whether or not a new tween that is overwriting this one should be re-initted() with the changed properties.
  473. */
  474. protected function removePropTween(propTween:PropTween):Boolean {
  475. if (propTween.nextNode) {
  476. propTween.nextNode.prevNode = propTween.prevNode;
  477. }
  478. if (propTween.prevNode) {
  479. propTween.prevNode.nextNode = propTween.nextNode;
  480. } else if (this.cachedPT1 == propTween) {
  481. this.cachedPT1 = propTween.nextNode;
  482. }
  483. if (propTween.isPlugin && propTween.target.onDisable) {
  484. propTween.target.onDisable(); //some plugins need to be notified so they can perform cleanup tasks first
  485. if (propTween.target.activeDisable) {
  486. return true;
  487. }
  488. }
  489. return false;
  490. }
  491. /** @inheritDoc **/
  492. override public function invalidate():void {
  493. this.yoyo = Boolean(this.vars.yoyo == true);
  494. _repeat = (this.vars.repeat) ? Number(this.vars.repeat) : 0;
  495. _repeatDelay = (this.vars.repeatDelay) ? Number(this.vars.repeatDelay) : 0;
  496. _hasUpdateListener = false;
  497. if (this.vars.onCompleteListener != null || this.vars.onUpdateListener != null || this.vars.onStartListener != null) {
  498. initDispatcher();
  499. }
  500. setDirtyCache(true);
  501. super.invalidate();
  502. }
  503. /**
  504. * Updates tweening values on the fly so that they appear to seamlessly change course even if the tween is in-progress.
  505. * Think of it as dynamically updating the <code>vars</code> object that you passed in to the tween when it was originally
  506. * created. You do <b>NOT</b> need to redefine all of the <code>vars</code> values - only the ones that you want
  507. * to update. You can even define new properties that you didn't define in the original <code>vars</code> object.
  508. * If the <code>resetDuration</code> parameter is <code>true</code> and the tween has already started (or finished),
  509. * <code>updateTo()</code> will restart the tween. Otherwise, the tween's timing will be honored. And if
  510. * <code>resetDuration</code> is <code>false</code> and the tween is in-progress, the starting values of each
  511. * property will be adjusted so that the tween appears to seamlessly redirect to the new destination values.
  512. * For example:<br /><br /><code>
  513. *
  514. * //create the tween <br />
  515. * var tween:TweenMax = new TweenMax(mc, 2, {x:100, y:200, alpha:0.5});<br /><br />
  516. *
  517. * //then later, update the destination x and y values, restarting the tween<br />
  518. * tween.updateTo({x:300, y:0}, true);<br /><br />
  519. *
  520. * //or to update the values mid-tween while keeping the end time the same (don't restart the tween), do this:<br />
  521. * tween.updateTo({x:300, y:0}, false);<br /><br /></code>
  522. *
  523. * Note: If you plan to constantly update values, please look into using the <code>DynamicPropsPlugin</code>.
  524. *
  525. * @param vars Object containing properties with the end values that should be udpated. You do <b>NOT</b> need to redefine all of the original <code>vars</code> values - only the ones that should be updated (although if you change a plugin value, you will need to fully define it). For example, to update the destination <code>x</code> value to 300 and the destination <code>y</code> value to 500, pass: <code>{x:300, y:500}</code>.
  526. * @param resetDuration If the tween has already started (or finished) and <code>resetDuration</code> is true, the tween will restart. If <code>resetDuration</code> is false, the tween's timing will be honored (no restart) and each tweening property's starting value will be adjusted so that it appears to seamlessly redirect to the new destination value.
  527. **/
  528. public function updateTo(vars:Object, resetDuration:Boolean=false):void {
  529. var curRatio:Number = this.ratio;
  530. if (resetDuration && this.timeline != null && this.cachedStartTime < this.timeline.cachedTime) {
  531. this.cachedStartTime = this.timeline.cachedTime;
  532. this.setDirtyCache(false);
  533. if (this.gc) {
  534. this.setEnabled(true, false);
  535. } else {
  536. this.timeline.addChild(this); //ensures that any necessary re-sequencing of TweenCores in the timeline occurs to make sure the rendering order is correct.
  537. }
  538. }
  539. for (var p:String in vars) {
  540. this.vars[p] = vars[p];
  541. }
  542. if (this.initted) {
  543. this.initted = false;
  544. if (!resetDuration) {
  545. init();
  546. if (!resetDuration && this.cachedTime > 0 && this.cachedTime < this.cachedDuration) {
  547. var inv:Number = 1 / (1 - curRatio);
  548. var pt:PropTween = this.cachedPT1, endValue:Number;
  549. while (pt) {
  550. endValue = pt.start + pt.change;
  551. pt.change *= inv;
  552. pt.start = endValue - pt.change;
  553. pt = pt.nextNode;
  554. }
  555. }
  556. }
  557. }
  558. }
  559. /**
  560. * Adjusts a destination value on the fly, optionally adjusting the start values so that it appears to redirect seamlessly
  561. * without skipping/jerking (<b>this method has been deprecated in favor of <code>updateTo()</code></b>).
  562. * If you plan to constantly update values, please look into using the DynamicPropsPlugin.
  563. *
  564. * @param property Name of the property that should be updated. For example, "x".
  565. * @param value The new destination value
  566. * @param adjustStartValues If true, the property's start value will be adjusted to make the tween appear to seamlessly/smoothly redirect without any skipping/jerking. Beware that if start values are adjusted, reversing the tween will not make it travel back to the original starting value.
  567. **/
  568. public function setDestination(property:String, value:*, adjustStartValues:Boolean=true):void {
  569. var vars:Object = {};
  570. vars[property] = value;
  571. updateTo(vars, !adjustStartValues);
  572. }
  573. /**
  574. * Allows particular properties of the tween to be killed, much like the killVars() method
  575. * except that killProperties() accepts an Array of property names.
  576. *
  577. * @param names An Array of property names whose tweens should be killed immediately.
  578. */
  579. public function killProperties(names:Array):void {
  580. var v:Object = {}, i:int = names.length;
  581. while (--i > -1) {
  582. v[names[i]] = true;
  583. }
  584. killVars(v);
  585. }
  586. /**
  587. * @private
  588. * Renders the tween at a particular time (or frame number for frames-based tweens).
  589. * The time is based simply on the overall duration. For example, if a tween's duration
  590. * is 3, <code>renderTime(1.5)</code> would render it at the halfway finished point.
  591. *
  592. * @param time time (or frame number for frames-based tweens) to render.
  593. * @param suppressEvents If true, no events or callbacks will be triggered for this render (like onComplete, onUpdate, onReverseComplete, etc.)
  594. * @param force Normally the tween will skip rendering if the time matches the cachedTotalTime (to improve performance), but if force is true, it forces a render. This is primarily used internally for tweens with durations of zero in TimelineLite/Max instances.
  595. */
  596. override public function renderTime(time:Number, suppressEvents:Boolean=false, force:Boolean=false):void {
  597. var totalDur:Number = (this.cacheIsDirty) ? this.totalDuration : this.cachedTotalDuration, prevTime:Number = this.cachedTime, isComplete:Boolean, repeated:Boolean, setRatio:Boolean;
  598. if (time >= totalDur) {
  599. this.cachedTotalTime = totalDur;
  600. this.cachedTime = this.cachedDuration;
  601. this.ratio = 1;
  602. isComplete = true;
  603. if (this.cachedDuration == 0) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
  604. if ((time == 0 || _rawPrevTime < 0) && _rawPrevTime != time) {
  605. force = true;
  606. }
  607. _rawPrevTime = time;
  608. }
  609. } else if (time <= 0) {
  610. if (time < 0) {
  611. this.active = false;
  612. if (this.cachedDuration == 0) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
  613. if (_rawPrevTime > 0) {
  614. force = true;
  615. isComplete = true;
  616. }
  617. _rawPrevTime = time;
  618. }
  619. }
  620. this.cachedTotalTime = this.cachedTime = this.ratio = 0;
  621. if (this.cachedReversed && prevTime != 0) {
  622. isComplete = true;
  623. }
  624. } else {
  625. this.cachedTotalTime = this.cachedTime = time;
  626. setRatio = true;
  627. }
  628. if (_repeat != 0) {
  629. var cycleDuration:Number = this.cachedDuration + _repeatDelay;
  630. if (isComplete) {
  631. if (this.yoyo && _repeat % 2) {
  632. this.cachedTime = this.ratio = 0;
  633. }
  634. } else if (time > 0) {
  635. var prevCycles:int = _cyclesComplete;
  636. _cyclesComplete = int(this.cachedTotalTime / cycleDuration);
  637. if (_cyclesComplete == this.cachedTotalTime / cycleDuration) {
  638. _cyclesComplete--; //otherwise when rendered exactly at the end time, it will act as though it is repeating (at the beginning)
  639. }
  640. if (prevCycles != _cyclesComplete) {
  641. repeated = true;
  642. }
  643. this.cachedTime = ((this.cachedTotalTime / cycleDuration) - _cyclesComplete) * cycleDuration; //originally this.cachedTotalTime % cycleDuration but floating point errors caused problems, so I normalized it. (4 % 0.8 should be 0 but Flash reports it as 0.79999999!)
  644. if (this.yoyo && _cyclesComplete % 2) {
  645. this.cachedTime = this.cachedDuration - this.cachedTime;
  646. } else if (this.cachedTime >= this.cachedDuration) {
  647. this.cachedTime = this.cachedDuration;
  648. this.ratio = 1;
  649. setRatio = false;
  650. }
  651. if (this.cachedTime <= 0) {
  652. this.cachedTime = this.ratio = 0;
  653. setRatio = false;
  654. }
  655. }
  656. }
  657. if (prevTime == this.cachedTime && !force) {
  658. return;
  659. } else if (!this.initted) {
  660. init();
  661. }
  662. if (!this.active && !this.cachedPaused) {
  663. this.active = true; //so that if the user renders a tween (as opposed to the timeline rendering it), the timeline is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the tween already finished but the user manually re-renders it as halfway done.
  664. }
  665. if (setRatio) {
  666. //if the ease is optimized, process it inline (function calls are expensive performance-wise)...
  667. if (_easeType) {
  668. var power:int = _easePower;
  669. var val:Number = this.cachedTime / this.cachedDuration;
  670. if (_easeType == 2) { //easeOut
  671. this.ratio = val = 1 - val;
  672. while (--power > -1) {
  673. this.ratio = val * this.ratio;
  674. }
  675. this.ratio = 1 - this.ratio;
  676. } else if (_easeType == 1) { //easeIn
  677. this.ratio = val;
  678. while (--power > -1) {
  679. this.ratio = val * this.ratio;
  680. }
  681. } else { //easeInOut
  682. if (val < 0.5) {
  683. this.ratio = val = val * 2;
  684. while (--power > -1) {
  685. this.ratio = val * this.ratio;
  686. }
  687. this.ratio = this.ratio * 0.5;
  688. } else {
  689. this.ratio = val = (1 - val) * 2;
  690. while (--power > -1) {
  691. this.ratio = val * this.ratio;
  692. }
  693. this.ratio = 1 - (0.5 * this.ratio);
  694. }
  695. }
  696. } else {
  697. this.ratio = _ease(this.cachedTime, 0, 1, this.cachedDuration);
  698. }
  699. }
  700. if (prevTime == 0 && this.cachedTotalTime != 0 && !suppressEvents) {
  701. if (this.vars.onStart) {
  702. this.vars.onStart.apply(null, this.vars.onStartParams);
  703. }
  704. if (_dispatcher) {
  705. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.START));
  706. }
  707. }
  708. var pt:PropTween = this.cachedPT1;
  709. while (pt) {
  710. pt.target[pt.property] = pt.start + (this.ratio * pt.change);
  711. pt = pt.nextNode;
  712. }
  713. if (_hasUpdate && !suppressEvents) {
  714. this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
  715. }
  716. if (_hasUpdateListener && !suppressEvents) {
  717. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.UPDATE));
  718. }
  719. if (isComplete) {
  720. if (_hasPlugins && this.cachedPT1) {
  721. onPluginEvent("onComplete", this);
  722. }
  723. complete(true, suppressEvents);
  724. } else if (repeated && !suppressEvents) {
  725. if (this.vars.onRepeat) {
  726. this.vars.onRepeat.apply(null, this.vars.onRepeatParams);
  727. }
  728. if (_dispatcher) {
  729. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.REPEAT));
  730. }
  731. }
  732. }
  733. /**
  734. * Forces the tween to completion.
  735. *
  736. * @param skipRender to skip rendering the final state of the tween, set skipRender to true.
  737. * @param suppressEvents If true, no events or callbacks will be triggered for this render (like onComplete, onUpdate, onReverseComplete, etc.)
  738. */
  739. override public function complete(skipRender:Boolean=false, suppressEvents:Boolean=false):void {
  740. super.complete(skipRender, suppressEvents);
  741. if (!suppressEvents && _dispatcher) {
  742. if (this.cachedTotalTime == this.cachedTotalDuration && !this.cachedReversed) {
  743. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.COMPLETE));
  744. } else if (this.cachedReversed && this.cachedTotalTime == 0) {
  745. _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.REVERSE_COMPLETE));
  746. }
  747. }
  748. }
  749. //---- EVENT DISPATCHING ----------------------------------------------------------------------------------------------------------
  750. /**
  751. * @private
  752. * Initializes Event dispatching functionality
  753. */
  754. protected function initDispatcher():void {
  755. if (_dispatcher == null) {
  756. _dispatcher = new EventDispatcher(this);
  757. }
  758. if (this.vars.onInitListener is Function) {
  759. _dispatcher.addEventListener(TweenEvent.INIT, this.vars.onInitListener, false, 0, true);
  760. }
  761. if (this.vars.onStartListener is Function) {
  762. _dispatcher.addEventListener(TweenEvent.START, this.vars.onStartListener, false, 0, true);
  763. }
  764. if (this.vars.onUpdateListener is Function) {
  765. _dispatcher.addEventListener(TweenEvent.UPDATE, this.vars.onUpdateListener, false, 0, true);
  766. _hasUpdateListener = true;
  767. }
  768. if (this.vars.onCompleteListener is Function) {
  769. _dispatcher.addEventListener(TweenEvent.COMPLETE, this.vars.onCompleteListener, false, 0, true);
  770. }
  771. if (this.vars.onRepeatListener is Function) {
  772. _dispatcher.addEventListener(TweenEvent.REPEAT, this.vars.onRepeatListener, false, 0, true);
  773. }
  774. if (this.vars.onReverseCompleteListener is Function) {
  775. _dispatcher.addEventListener(TweenEvent.REVERSE_COMPLETE, this.vars.onReverseCompleteListener, false, 0, true);
  776. }
  777. }
  778. /** @private **/
  779. public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void {
  780. if (_dispatcher == null) {
  781. initDispatcher();
  782. }
  783. if (type == TweenEvent.UPDATE) {
  784. _hasUpdateListener = true;
  785. }
  786. _dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
  787. }
  788. /** @private **/
  789. public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
  790. if (_dispatcher) {
  791. _dispatcher.removeEventListener(type, listener, useCapture);
  792. }
  793. }
  794. /** @private **/
  795. public function hasEventListener(type:String):Boolean {
  796. return (_dispatcher == null) ? false : _dispatcher.hasEventListener(type);
  797. }
  798. /** @private **/
  799. public function willTrigger(type:String):Boolean {
  800. return (_dispatcher == null) ? false : _dispatcher.willTrigger(type);
  801. }
  802. /** @private **/
  803. public function dispatchEvent(e:Event):Boolean {
  804. return (_dispatcher == null) ? false : _dispatcher.dispatchEvent(e);
  805. }
  806. //---- STATIC FUNCTIONS -----------------------------------------------------------------------------------------------------------
  807. /**
  808. * Static method for creating a TweenMax instance. This can be more intuitive for some developers
  809. * and shields them from potential garbage collection issues that could arise when assigning a
  810. * tween instance to a variable that persists. The following lines of code produce exactly
  811. * the same result: <br /><br /><code>
  812. *
  813. * var myTween:TweenMax = new TweenMax(mc, 1, {x:100}); <br />
  814. * TweenMax.to(mc, 1, {x:100}); <br />
  815. * var myTween:TweenMax = TweenMax.to(mc, 1, {x:100}); <br /><br /></code>
  816. *
  817. * @param target Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
  818. * @param duration Duration in seconds (or in frames for frames-based tweens)
  819. * @param vars An object containing the end values of the properties you're tweening. For example, to tween to x=100, y=100, you could pass {x:100, y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
  820. * @return TweenMax instance
  821. */
  822. public static function to(target:Object, duration:Number, vars:Object):TweenMax {
  823. return new TweenMax(target, duration, vars);
  824. }
  825. /**
  826. * Static method for creating a TweenMax instance that tweens in the opposite direction
  827. * compared to a <code>TweenMax.to()</code> tween. In other words, you define the START values in the
  828. * vars object instead of the end values, and the tween will use the current values as
  829. * the end values. This can be very useful for animating things into place on the stage
  830. * because you can build them in their end positions and do some simple <code>TweenMax.from()</code>
  831. * calls to animate them into place. <b>NOTE:</b> By default, <code>immediateRender</code>
  832. * is <code>true</code> for from() tweens, meaning that they immediately render their starting state
  833. * regardless of any delay that is specified. You can override this behavior by passing
  834. * <code>immediateRender:false</code> in the <code>vars</code> object so that it will wait to
  835. * render until the tween actually begins (often the desired behavior when inserting into timelines).
  836. * To illustrate the default behavior, the following code will immediately set the <code>alpha</code> of <code>mc</code>
  837. * to 0 and then wait 2 seconds before tweening the <code>alpha</code> back to 1 over the course
  838. * of 1.5 seconds:<br /><br /><code>
  839. *
  840. * TweenMax.from(mc, 1.5, {alpha:0, delay:2});</code>
  841. *
  842. * @param target Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
  843. * @param duration Duration in seconds (or in frames for frames-based tweens)
  844. * @param vars An object containing the start values of the properties you're tweening. For example, to tween from x=100, y=100, you could pass {x:100, y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
  845. * @return TweenMax instance
  846. */
  847. public static function from(target:Object, duration:Number, vars:Object):TweenMax {
  848. vars.runBackwards = true;
  849. if (!("immediateRender" in vars)) {
  850. vars.immediateRender = true;
  851. }
  852. return new TweenMax(target, duration, vars);
  853. }
  854. /**
  855. * Static method for creating a TweenMax instance that tweens from a particular set of
  856. * values to another set of values, as opposed to a normal to() or from() tween which are
  857. * based on the target's current values. <b>NOTE</b>: Only put starting values
  858. * in the fromVars parameter - all special properties for the tween (like onComplete, onUpdate, delay, etc.) belong
  859. * in the toVars parameter.
  860. *
  861. * @param target Target object whose properties this tween affects. This can be ANY object, not just a DisplayObject.
  862. * @param duration Duration in seconds (or in frames for frames-based tweens)
  863. * @param fromVars An object containing the starting values of the properties you're tweening. For example, to tween from x=0, y=0, you could pass {x:0, y:0}. Only put starting values in the fromVars parameter - all special properties for the tween (like onComplete, onUpdate, delay, etc.) belong in the toVars parameter.
  864. * @param toVars An object containing the ending values of the properties you're tweening. For example, to tween to x=100, y=100, you could pass {x:100, y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
  865. * @return TweenMax instance
  866. */
  867. public static function fromTo(target:Object, duration:Number, fromVars:Object, toVars:Object):TweenMax {
  868. toVars.startAt = fromVars;
  869. if (fromVars.immediateRender) {
  870. toVars.immediateRender = true;
  871. }
  872. return new TweenMax(target, duration, toVars);
  873. }
  874. /**
  875. * Tween multiple objects to the same end values. The "stagger" parameter
  876. * staggers the start time of each tween. For example, you might want to have 5 MovieClips move down
  877. * 100 pixels while fading out, and stagger the start times slightly by 0.2 seconds: <br /><br /><code>
  878. *
  879. * TweenMax.allTo([mc1, mc2, mc3, mc4, mc5], 1, {y:"100", alpha:0}, 0.2); <br /><br /></code>
  880. *
  881. * Note: You can easily add a group of tweens to a TimelineLite/Max instance using allTo() in conjunction with the
  882. * insertMultipe() method of a timeline, like:<br /><br />
  883. * <code>myTimeline.insertMultiple(TweenMax.allTo([mc1, mc2, mc3], 1, {alpha:0, y:"100"}, 0.1));</code>
  884. *
  885. * @param targets An Array of objects to tween.
  886. * @param duration Duration in seconds (or frames for frames-based tweens) of the tween
  887. * @param vars An object containing the end values of all the properties you'd like to have tweened (or if you're using the TweenMax.allFrom() method, these variables would define the BEGINNING values).
  888. * @param stagger Staggers the start time of each tween. For example, you might want to have 5 MovieClips move down 100 pixels while fading out, and stagger the start times slightly by 0.2 seconds, you could do: <code>TweenMax.allTo([mc1, mc2, mc3, mc4, mc5], 1, {y:"100", alpha:0}, 0.2)</code>.
  889. * @param onCompleteAll A function to call when all of the tweens have completed.
  890. * @param onCompleteAllParams An Array of parameters to pass the onCompleteAll function when all the tweens have completed.
  891. * @return Array of TweenMax tweens
  892. */
  893. public static function allTo(targets:Array, duration:Number, vars:Object, stagger:Number=0, onCompleteAll:Function=null, onCompleteAllParams:Array=null):Array {
  894. var i:int, varsDup:Object, p:String;
  895. var l:uint = targets.length;
  896. var a:Array = [];
  897. var curDelay:Number = ("delay" in vars) ? Number(vars.delay) : 0;
  898. var onCompleteProxy:Function = vars.onComplete;
  899. var onCompleteParamsProxy:Array = vars.onCompleteParams;
  900. var lastIndex:int = (stagger <= 0) ? 0 : l - 1;
  901. for (i = 0; i < l; i++) {
  902. varsDup = {};
  903. for (p in vars) {
  904. varsDup[p] = vars[p];
  905. }
  906. varsDup.delay = curDelay;
  907. if (i == lastIndex && onCompleteAll != null) {
  908. varsDup.onComplete = function():void {
  909. if (onCompleteProxy != null) {
  910. onCompleteProxy.apply(null, onCompleteParamsProxy);
  911. }
  912. onCompleteAll.apply(null, onCompleteAllParams);
  913. }
  914. }
  915. a[a.length] = new TweenMax(targets[i], duration, varsDup);
  916. curDelay += stagger;
  917. }
  918. return a;
  919. }
  920. /**
  921. * Exactly the same as TweenMax.allTo(), but instead of tweening the properties from where they're
  922. * at currently to whatever you define, this tweens them the opposite way - from where you define TO
  923. * where ever they are when the tweens begin. This is useful when things are set up on the stage the way they should
  924. * end up and you just want to tween them into place. <b>NOTE:</b> By default, <code>immediateRender</code>
  925. * is <code>true</code> for allFrom() tweens, meaning that they immediately render their starting state
  926. * regardless of any delay or stagger that is specified. You can override this behavior by passing
  927. * <code>immediateRender:false</code> in the <code>vars</code> object so that each tween will wait to render until
  928. * any delay/stagger has passed (often the desired behavior when inserting into timelines). To illustrate
  929. * the default behavior, the following code will immediately set the <code>alpha</code> of <code>mc1</code>,
  930. * <code>mc2</code>, and <code>mc3</code> to 0 and then wait 2 seconds before tweening each <code>alpha</code>
  931. * back to 1 over the course of 1.5 seconds with 0.1 seconds lapsing between the start times of each:<br /><br /><code>
  932. *
  933. * TweenMax.allFrom([mc1, mc2, mc3], 1.5, {alpha:0, delay:2}, 0.1);</code>
  934. *
  935. * @param targets An Array of objects to tween.
  936. * @param duration Duration (in seconds) of the tween (or in frames for frames-based tweens)
  937. * @param vars An object containing the start values of all the properties you'd like to have tweened.
  938. * @param stagger Staggers the start time of each tween. For example, you might want to have 5 MovieClips move down 100 pixels while fading from alpha:0, and stagger the start times slightly by 0.2 seconds, you could do: <code>TweenMax.allFromTo([mc1, mc2, mc3, mc4, mc5], 1, {y:"-100", alpha:0}, 0.2)</code>.
  939. * @param onCompleteAll A function to call when all of the tweens have completed.
  940. * @param onCompleteAllParams An Array of parameters to pass the onCompleteAll function when all the tweens have completed.
  941. * @return Array of TweenMax instances
  942. */
  943. public static function allFrom(targets:Array, duration:Number, vars:Object, stagger:Number=0, onCompleteAll:Function=null, onCompleteAllParams:Array=null):Array {
  944. vars.runBackwards = true;
  945. if (!("immediateRender" in vars)) {
  946. vars.immediateRender = true;
  947. }
  948. return allTo(targets, duration, vars, stagger, onCompleteAll, onCompleteAllParams);
  949. }
  950. /**
  951. * Tweens multiple targets from a common set of starting values to a common set of ending values; exactly the same
  952. * as TweenMax.allTo(), but adds the ability to define the starting values. <b>NOTE</b>: Only put starting values
  953. * in the fromVars parameter - all special properties for the tween (like onComplete, onUpdate, delay, etc.) belong
  954. * in the toVars parameter.
  955. *
  956. * @param targets An Array of objects to tween.
  957. * @param duration Duration (in seconds) of the tween (or in frames for frames-based tweens)
  958. * @param fromVars An object containing the starting values of all the properties you'd like to have tweened.
  959. * @param toVars An object containing the ending values of all the properties you'd like to have tweened.
  960. * @param stagger Staggers the start time of each tween. For example, you might want to have 5 MovieClips move down from y:0 to y:100 while fading from alpha:0 to alpha:1, and stagger the start times slightly by 0.2 seconds, you could do: <code>TweenMax.allFromTo([mc1, mc2, mc3, mc4, mc5], 1, {y:0, alpha:0}, {y:100, alpha:1}, 0.2)</code>.
  961. * @param onCompleteAll A function to call when all of the tweens have completed.
  962. * @param onCompleteAllParams An Array of parameters to pass the onCompleteAll function when all the tweens have completed.
  963. * @return Array of TweenMax instances
  964. */
  965. public static function allFromTo(targets:Array, duration:Number, fromVars:Object, toVars:Object, stagger:Number=0, onCompleteAll:Function=null, onCompleteAllParams:Array=null):Array {
  966. toVars.startAt = fromVars;
  967. if (fromVars.immediateRender) {
  968. toVars.immediateRender = true;
  969. }
  970. return allTo(targets, duration, toVars, stagger, onCompleteAll, onCompleteAllParams);
  971. }
  972. /**
  973. * Provides a simple way to call a function after a set amount of time (or frames). You can
  974. * optionally pass any number of parameters to the function too. For example: <br /><br /><code>
  975. *
  976. * TweenMax.delayedCall(1, myFunction, ["param1", 2]);<br />
  977. * function myFunction(param1:String, param2:Number):void {<br />
  978. * trace("called myFunction and passed params: " + param1 + ", " + param2);<br />
  979. * }<br /><br /></code>
  980. *
  981. * @param delay Delay in seconds (or frames if useFrames is true) before the function should be called
  982. * @param onComplete Function to call
  983. * @param onCompleteParams An Array of parameters to pass the function.
  984. * @return TweenMax instance
  985. */
  986. public static function delayedCall(delay:Number, onComplete:Function, onCompleteParams:Array=null, useFrames:Boolean=false):TweenMax {
  987. return new TweenMax(onComplete, 0, {delay:delay, onComplete:onComplete, onCompleteParams:onCompleteParams, immediateRender:false, useFrames:useFrames, overwrite:0});
  988. }
  989. /**
  990. * Gets all the tweens of a particular object.
  991. *
  992. * @param target The target object whose tweens you want returned
  993. * @return Array of tweens (could be TweenLite and/or TweenMax instances)
  994. */
  995. public static function getTweensOf(target:Object):Array {
  996. var a:Array = masterList[target];
  997. var toReturn:Array = [];
  998. if (a) {
  999. var i:int = a.length;
  1000. var cnt:uint = 0;
  1001. while (--i > -1) {
  1002. if (!a[i].gc) {
  1003. toReturn[cnt++] = a[i];
  1004. }
  1005. }
  1006. }
  1007. return toReturn;
  1008. }
  1009. /**
  1010. * Determines whether or not a particular object is actively tweening. If a tween
  1011. * is paused or hasn't started yet, it doesn't count as active.
  1012. *
  1013. * @param target Target object whose tweens you're checking
  1014. * @return Boolean value indicating whether or not any active tweens were found
  1015. */
  1016. public static function isTweening(target:Object):Boolean {
  1017. var a:Array = getTweensOf(target);
  1018. var i:int = a.length;
  1019. var tween:TweenLite;
  1020. while (--i > -1) {
  1021. tween = a[i];
  1022. if ((tween.active || (tween.cachedStartTime == tween.timeline.cachedTime && tween.timeline.active))) {
  1023. return true;
  1024. }
  1025. }
  1026. return false;
  1027. }
  1028. /**
  1029. * Returns all tweens that are in the masterList. Tweens are automatically removed from the
  1030. * masterList when they complete and are not attached to a timeline that has
  1031. * autoRemoveChildren set to true.
  1032. *
  1033. * @return Array of TweenLite and/or TweenMax instances
  1034. */
  1035. public static function getAllTweens():Array {
  1036. var ml:Dictionary = masterList; //speeds things up slightly
  1037. var cnt:uint = 0;
  1038. var toReturn:Array = [], a:Array, i:int;
  1039. for each (a in ml) {
  1040. i = a.length;
  1041. while (--i > -1) {
  1042. if (!TweenLite(a[i]).gc) {
  1043. toReturn[cnt++] = a[i];
  1044. }
  1045. }
  1046. }
  1047. return toReturn;
  1048. }
  1049. /**
  1050. * Kills all tweens and/or delayedCalls/callbacks, optionally forcing them to completion first.
  1051. *
  1052. * @param complete Determines whether or not the tweens/delayedCalls/callbacks should be forced to completion before being killed.
  1053. * @param tweens If true, all tweens will be killed
  1054. * @param delayedCalls If true, all delayedCalls will be killed. TimelineMax callbacks are treated the same as delayedCalls.
  1055. */
  1056. public static function killAll(complete:Boolean=false, tweens:Boolean=true, delayedCalls:Boolean=true):void {
  1057. var a:Array = getAllTweens();
  1058. var isDC:Boolean; //is delayedCall
  1059. var i:int = a.length;
  1060. while (--i > -1) {
  1061. isDC = (a[i].target == a[i].vars.onComplete);
  1062. if (isDC == delayedCalls || isDC != tweens) {
  1063. if (complete) {
  1064. a[i].complete(false);
  1065. } else {
  1066. a[i].setEnabled(false, false);
  1067. }
  1068. }
  1069. }
  1070. }
  1071. /**
  1072. * Kills all tweens of the children of a particular DisplayObjectContainer, optionally forcing them to completion first.
  1073. *
  1074. * @param parent The DisplayObjectContainer whose children should no longer be affected by any tweens.
  1075. * @param complete Determines whether or not the tweens should be forced to completion before being killed.
  1076. */
  1077. public static function killChildTweensOf(parent:DisplayObjectContainer, complete:Boolean=false):void {
  1078. var a:Array = getAllTweens();
  1079. var curTarget:Object, curParent:DisplayObjectContainer;
  1080. var i:int = a.length;
  1081. while (--i > -1) {
  1082. curTarget = a[i].target;
  1083. if (curTarget is DisplayObject) {
  1084. curParent = curTarget.parent;
  1085. while (curParent) {
  1086. if (curParent == parent) {
  1087. if (complete) {
  1088. a[i].complete(false);
  1089. } else {
  1090. a[i].setEnabled(false, false);
  1091. }
  1092. }
  1093. curParent = curParent.parent;
  1094. }
  1095. }
  1096. }
  1097. }
  1098. /**
  1099. * Pauses all tweens and/or delayedCalls/callbacks.
  1100. *
  1101. * @param tweens If true, all tweens will be paused.
  1102. * @param delayedCalls If true, all delayedCalls will be paused. TimelineMax callbacks are treated the same as delayedCalls.
  1103. */
  1104. public static function pauseAll(tweens:Boolean=true, delayedCalls:Boolean=true):void {
  1105. changePause(true, tweens, delayedCalls);
  1106. }
  1107. /**
  1108. * Resumes all paused tweens and/or delayedCalls/callbacks.
  1109. *
  1110. * @param tweens If true, all tweens will be resumed.
  1111. * @param delayedCalls If true, all delayedCalls will be resumed. TimelineMax callbacks are treated the same as delayedCalls.
  1112. */
  1113. public static function resumeAll(tweens:Boolean=true, delayedCalls:Boolean=true):void {
  1114. changePause(false, tweens, delayedCalls);
  1115. }
  1116. /**
  1117. * @private
  1118. * Changes the paused state of all tweens and/or delayedCalls/callbacks
  1119. *
  1120. * @param pause Desired paused state
  1121. * @param tweens If true, all tweens will be affected.
  1122. * @param delayedCalls If true, all delayedCalls will be affected. TimelineMax callbacks are treated the same as delayedCalls.
  1123. */
  1124. private static function changePause(pause:Boolean, tweens:Boolean=true, delayedCalls:Boolean=false):void {
  1125. var a:Array = getAllTweens();
  1126. var isDC:Boolean; //is delayedCall
  1127. var i:int = a.length;
  1128. while (--i > -1) {
  1129. isDC = (TweenLite(a[i]).target == TweenLite(a[i]).vars.onComplete);
  1130. if (isDC == delayedCalls || isDC != tweens) {
  1131. TweenCore(a[i]).paused = pause;
  1132. }
  1133. }
  1134. }
  1135. //---- GETTERS / SETTERS ----------------------------------------------------------------------------------------------------------
  1136. /**
  1137. * Value between 0 and 1 indicating the progress of the tween according to its <code>duration</code>
  1138. * where 0 is at the beginning, 0.5 is halfway finished, and 1 is finished. <code>totalProgress</code>,
  1139. * by contrast, describes the overall progress according to the tween's <code>totalDuration</code>
  1140. * which includes repeats and repeatDelays (if there are any). For example, if a TweenMax instance
  1141. * is set to repeat once, at the end of the first cycle <code>totalProgress</code> would only be 0.5
  1142. * whereas <code>currentProgress</code> would be 1. If you tracked both properties over the course of the
  1143. * tween, you'd see <code>currentProgress</code> go from 0 to 1 twice (once for each cycle) in the same
  1144. * time it takes the <code>totalProgress</code> property to go from 0 to 1 once.
  1145. **/
  1146. public function get currentProgress():Number {
  1147. return this.cachedTime / this.duration;
  1148. }
  1149. public function set currentProgress(n:Number):void {
  1150. if (_cyclesComplete == 0) {
  1151. setTotalTime(this.duration * n, false);
  1152. } else {
  1153. setTotalTime(this.duration * n + (_cyclesComplete * this.cachedDuration), false);
  1154. }
  1155. }
  1156. /**
  1157. * Value between 0 and 1 indicating the overall progress of the tween according to its <code>totalDuration</code>
  1158. * where 0 is at the beginning, 0.5 is halfway finished, and 1 is finished. <code>currentProgress</code>,
  1159. * by contrast, describes the progress according to the tween's <code>duration</code> which does not
  1160. * include repeats and repeatDelays. For example, if a TweenMax instance is set to repeat
  1161. * once, at the end of the first cycle <code>totalProgress</code> would only be 0.5
  1162. * whereas <code>currentProgress</code> would be 1. If you tracked both properties over the course of the
  1163. * tween, you'd see <code>currentProgress</code> go from 0 to 1 twice (once for each cycle) in the same
  1164. * time it takes the <code>totalProgress</code> property to go from 0 to 1 once.
  1165. **/
  1166. public function get totalProgress():Number {
  1167. return this.cachedTotalTime / this.totalDuration;
  1168. }
  1169. public function set totalProgress(n:Number):void {
  1170. setTotalTime(this.totalDuration * n, false);
  1171. }
  1172. /**
  1173. * Most recently rendered time (or frame for frames-based timelines) according to the tween's
  1174. * duration. <code>totalTime</code>, by contrast, is based on the <code>totalDuration</code> which includes repeats and repeatDelays.
  1175. * For example, if a TweenMax instance has a duration of 5 a repeat of 1 (meaning its
  1176. * <code>totalDuration</code> is 10), at the end of the second cycle, <code>currentTime</code> would be 5 whereas <code>totalTime</code>
  1177. * would be 10. If you tracked both properties over the course of the tween, you'd see <code>currentTime</code>
  1178. * go from 0 to 5 twice (one for each cycle) in the same time it takes <code>totalTime</code> go from 0 to 10.
  1179. */
  1180. override public function set currentTime(n:Number):void {
  1181. if (_cyclesComplete == 0) {
  1182. //no change needed
  1183. } else if (this.yoyo && (_cyclesComplete % 2 == 1)) {
  1184. n = (this.duration - n) + (_cyclesComplete * (this.cachedDuration + _repeatDelay));
  1185. } else {
  1186. n += (_cyclesComplete * (this.duration + _repeatDelay));
  1187. }
  1188. setTotalTime(n, false);
  1189. }
  1190. /**
  1191. * Duration of the tween in seconds (or frames for frames-based timelines) including any repeats
  1192. * or repeatDelays. <code>duration</code>, by contrast, does NOT include repeats and repeatDelays.
  1193. **/
  1194. override public function get totalDuration():Number {
  1195. if (this.cacheIsDirty) {
  1196. //instead of Infinity, we use 999999999999 so that we can accommodate reverses
  1197. this.cachedTotalDuration = (_repeat == -1) ? 999999999999 : this.cachedDuration * (_repeat + 1) + (_repeatDelay * _repeat);
  1198. this.cacheIsDirty = false;
  1199. }
  1200. return this.cachedTotalDuration;
  1201. }
  1202. override public function set totalDuration(n:Number):void {
  1203. if (_repeat == -1) {
  1204. return;
  1205. }
  1206. this.duration = (n - (_repeat * _repeatDelay)) / (_repeat + 1);
  1207. }
  1208. /** Multiplier describing the speed of the timeline where 1 is normal speed, 0.5 is half-speed, 2 is double speed, etc. **/
  1209. public function get timeScale():Number {
  1210. return this.cachedTimeScale;
  1211. }
  1212. public function set timeScale(n:Number):void {
  1213. if (n == 0) { //can't allow zero because it'll throw the math off
  1214. n = 0.0001;
  1215. }
  1216. var tlTime:Number = (_pauseTime || _pauseTime == 0) ? _pauseTime : this.timeline.cachedTotalTime;
  1217. this.cachedStartTime = tlTime - ((tlTime - this.cachedStartTime) * this.cachedTimeScale / n);
  1218. this.cachedTimeScale = n;
  1219. setDirtyCache(false);
  1220. }
  1221. /** Number of times that the tween should repeat; -1 repeats indefinitely. **/
  1222. public function get repeat():int {
  1223. return _repeat;
  1224. }
  1225. public function set repeat(n:int):void {
  1226. _repeat = n;
  1227. setDirtyCache(true);
  1228. }
  1229. /** Amount of time in seconds (or frames for frames-based tweens) between repeats **/
  1230. public function get repeatDelay():Number {
  1231. return _repeatDelay;
  1232. }
  1233. public function set repeatDelay(n:Number):void {
  1234. _repeatDelay = n;
  1235. setDirtyCache(true);
  1236. }
  1237. /** Multiplier describing the speed of the root timelines where 1 is normal speed, 0.5 is half-speed, 2 is double speed, etc. The lowest globalTimeScale possible is 0.0001. **/
  1238. public static function get globalTimeScale():Number {
  1239. return (TweenLite.rootTimeline == null) ? 1 : TweenLite.rootTimeline.cachedTimeScale;
  1240. }
  1241. public static function set globalTimeScale(n:Number):void {
  1242. if (n == 0) { //can't allow zero because it'll throw the math off
  1243. n = 0.0001;
  1244. }
  1245. if (TweenLite.rootTimeline == null) {
  1246. TweenLite.to({}, 0, {}); //forces initialization in case globalTimeScale is set before any tweens are created.
  1247. }
  1248. var tl:SimpleTimeline = TweenLite.rootTimeline;
  1249. var curTime:Number = (getTimer() * 0.001)
  1250. tl.cachedStartTime = curTime - ((curTime - tl.cachedStartTime) * tl.cachedTimeScale / n);
  1251. tl = TweenLite.rootFramesTimeline;
  1252. curTime = TweenLite.rootFrame;
  1253. tl.cachedStartTime = curTime - ((curTime - tl.cachedStartTime) * tl.cachedTimeScale / n);
  1254. TweenLite.rootFramesTimeline.cachedTimeScale = TweenLite.rootTimeline.cachedTimeScale = n;
  1255. }
  1256. }
  1257. }