Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleaning up

  • Loading branch information...
commit ee3722453c97bd847f3a2e753788f74fb6aff87a 1 parent 036e44b
@presstube authored
Showing with 0 additions and 12,285 deletions.
  1. +0 −379 src/com/greensock/OverwriteManager.as
  2. +0 −954 src/com/greensock/TimelineLite.as
  3. +0 −837 src/com/greensock/TimelineMax.as
  4. +0 −21 src/com/greensock/TweenAlign.as
  5. +0 −708 src/com/greensock/TweenLite.as
  6. +0 −1,331 src/com/greensock/TweenMax.as
  7. +0 −441 src/com/greensock/TweenNano.as
  8. +0 −627 src/com/greensock/changelog.txt
  9. +0 −61 src/com/greensock/core/PropTween.as
  10. +0 −104 src/com/greensock/core/SimpleTimeline.as
  11. +0 −404 src/com/greensock/core/TweenCore.as
  12. +0 −107 src/com/greensock/data/BevelFilterVars.as
  13. +0 −70 src/com/greensock/data/BlurFilterVars.as
  14. +0 −113 src/com/greensock/data/ColorMatrixFilterVars.as
  15. +0 −124 src/com/greensock/data/ColorTransformVars.as
  16. +0 −111 src/com/greensock/data/DropShadowFilterVars.as
  17. +0 −57 src/com/greensock/data/FilterVars.as
  18. +0 −96 src/com/greensock/data/GlowFilterVars.as
  19. +0 −54 src/com/greensock/data/TransformAroundCenterVars.as
  20. +0 −98 src/com/greensock/data/TransformAroundPointVars.as
  21. +0 −244 src/com/greensock/data/TweenLiteVars.as
  22. +0 −123 src/com/greensock/data/TweenMaxVars.as
  23. +0 −126 src/com/greensock/data/VarsCore.as
  24. +0 −14 src/com/greensock/easing/Back.as
  25. +0 −22 src/com/greensock/easing/Bounce.as
  26. +0 −14 src/com/greensock/easing/Circ.as
  27. +0 −17 src/com/greensock/easing/Cubic.as
  28. +0 −69 src/com/greensock/easing/EaseLookup.as
  29. +0 −28 src/com/greensock/easing/Elastic.as
  30. +0 −16 src/com/greensock/easing/Expo.as
  31. +0 −120 src/com/greensock/easing/FastEase.as
  32. +0 −19 src/com/greensock/easing/Linear.as
  33. +0 −17 src/com/greensock/easing/Quad.as
  34. +0 −17 src/com/greensock/easing/Quart.as
  35. +0 −17 src/com/greensock/easing/Quint.as
  36. +0 −204 src/com/greensock/easing/RoughEase.as
  37. +0 −15 src/com/greensock/easing/Sine.as
  38. +0 −17 src/com/greensock/easing/Strong.as
  39. +0 −21 src/com/greensock/easing/easing_readme.txt
  40. +0 −30 src/com/greensock/events/TweenEvent.as
  41. +0 −29 src/com/greensock/layout/AlignMode.as
  42. +0 −572 src/com/greensock/layout/AutoFitArea.as
  43. +0 −31 src/com/greensock/layout/ScaleMode.as
  44. +0 −227 src/com/greensock/motionPaths/Circle2D.as
  45. +0 −8 src/com/greensock/motionPaths/Direction.as
  46. +0 −371 src/com/greensock/motionPaths/MotionPath.as
  47. +0 −93 src/com/greensock/motionPaths/PathFollower.as
  48. +0 −69 src/com/greensock/plugins/AutoAlphaPlugin.as
  49. +0 −68 src/com/greensock/plugins/BevelFilterPlugin.as
  50. +0 −238 src/com/greensock/plugins/BezierPlugin.as
  51. +0 −73 src/com/greensock/plugins/BezierThroughPlugin.as
  52. +0 −62 src/com/greensock/plugins/BlurFilterPlugin.as
  53. +0 −114 src/com/greensock/plugins/Circle2DPlugin.as
  54. +0 −236 src/com/greensock/plugins/ColorMatrixFilterPlugin.as
  55. +0 −97 src/com/greensock/plugins/ColorTransformPlugin.as
  56. +0 −69 src/com/greensock/plugins/DropShadowFilterPlugin.as
  57. +0 −96 src/com/greensock/plugins/EndArrayPlugin.as
  58. +0 −106 src/com/greensock/plugins/EndVectorPlugin.as
  59. +0 −128 src/com/greensock/plugins/FilterPlugin.as
  60. +0 −61 src/com/greensock/plugins/FrameLabelPlugin.as
  61. +0 −62 src/com/greensock/plugins/FramePlugin.as
  62. +0 −67 src/com/greensock/plugins/GlowFilterPlugin.as
  63. +0 −110 src/com/greensock/plugins/HexColorsPlugin.as
  64. +0 −143 src/com/greensock/plugins/QuaternionsPlugin.as
  65. +0 −40 src/com/greensock/plugins/RemoveTintPlugin.as
  66. +0 −50 src/com/greensock/plugins/RoundPropsPlugin.as
  67. +0 −84 src/com/greensock/plugins/ScalePlugin.as
  68. +0 −83 src/com/greensock/plugins/ScrollRectPlugin.as
  69. +0 −91 src/com/greensock/plugins/SetActualSizePlugin.as
  70. +0 −90 src/com/greensock/plugins/SetSizePlugin.as
  71. +0 −70 src/com/greensock/plugins/ShortRotationPlugin.as
  72. +0 −64 src/com/greensock/plugins/SoundTransformPlugin.as
  73. +0 −94 src/com/greensock/plugins/TintPlugin.as
  74. +0 −224 src/com/greensock/plugins/TransformMatrixPlugin.as
  75. +0 −281 src/com/greensock/plugins/TweenPlugin.as
  76. +0 −72 src/com/greensock/plugins/VisiblePlugin.as
  77. +0 −63 src/com/greensock/plugins/VolumePlugin.as
  78. +0 −2  src/com/presstube/chunkulus/Chunklet.as
View
379 src/com/greensock/OverwriteManager.as
@@ -1,379 +0,0 @@
-/**
- * VERSION: 6.0
- * DATE: 10/1/2009
- * AS3 (AS2 is also available)
- * UPDATES AND DOCUMENTATION AT: http://blog.greensock.com/overwritemanager/
- **/
-package com.greensock {
- import com.greensock.core.*;
-
- import flash.errors.*;
- import flash.utils.*;
-/**
- * OverwriteManager resolves conflicts between tweens and controls if (and how) existing tweens of the same
- * target are overwritten. Think of it as a referee or traffic cop for tweens. For example, let's say you have
- * a button with <code>ROLL_OVER</code> and <code>ROLL_OUT</code> handlers that tween an object's alpha and the user rolls their mouse
- * over/out/over/out quickly. Most likely, you'd want each new tween to overwrite the other immediately so
- * that you don't end up with multiple tweens vying for control of the alpha property. That describes
- * the <code>ALL_IMMEDIATE</code> mode which is the default mode of TweenLite when it is not used in conjunction with
- * TweenMax, TimelineLite, or TimelineMax. This keeps things small and fast. However, it isn't ideal for
- * setting up sequences because as soon as you create subsequent tweens of the same target in the sequence,
- * the previous one gets overwritten. And what if you have a tween that is controling 3 properties and
- * then you create another tween that only controls one of those properties? You may want the first tween
- * to continue tweening the other 2 (non-overlapping) properties. This describes the <code>AUTO</code> mode which is
- * the default whenever TweenMax, TimelineLite, or TimelineMax is used in your swf. OverwriteManager
- * offers quite a few other modes to choose from in fact:
- *
- * <ul>
- * <li><b> NONE (0):</b>
- * <ol>
- * <li><b>When:</b> Never</li>
- * <li><b>Finds:</b> Nothing</li>
- * <li><b>Kills:</b> Nothing</li>
- * <li><b>Performance:</b> Excellent</li>
- * <li><b>Good for:</b> When you know that your tweens won't conflict and you want maximum speed.</li>
- * </ol>
- * </li>
- *
- * <li><b> ALL_IMMEDIATE (1):</b>
- * <ol>
- * <li><b>When:</b> Immediately when the tween is created.</li>
- * <li><b>Finds:</b> All tweens of the same target (regardless of timing or overlapping properties).</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Excellent</li>
- * <li><b>Good for:</b> When you want the tween to take priority over all other tweens of the
- * same target, like on button rollovers/rollouts. However, this mode is
- * bad for setting up sequences.</li>
- * </ol>
- * This is the default mode for TweenLite unless TweenMax, TimelineLite,
- * or TimelineMax are used in the SWF (in which case <code>AUTO</code> is the default mode).
- * </li>
- *
- * <li><b> AUTO (2):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> Only tweens of the same target that are active (running). Tweens that haven't started yet are immune.</li>
- * <li><b>Kills:</b> Only individual overlapping tweening properties. If all tweening properties
- * have been overwritten, the entire tween will be killed as well.</li>
- * <li><b>Performance:</b> Very good when there aren't many overlapping tweens; fair when there are.</li>
- * <li><b>Good for:</b> Virtually all situations. This mode does the best job overall of handling
- * overwriting in an intuitive way and is excellent for sequencing. </li>
- * </ol>
- * This is the default mode when TweenMax, TimelineLite, or TimelineMax is used in your swf (those classes
- * automatically init() OverwriteManager in <code>AUTO</code> mode unless you have already initted OverwriteManager manually).
- * </li>
- *
- * <li><b> CONCURRENT (3):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> Only tweens of the same target that are active (running). Tweens that haven't started yet are immune.</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Very good</li>
- * <li><b>Good for:</b> When you want the target object to only be controled by one tween at a time. Good
- * for sequencing although AUTO mode is typically better because it will only kill
- * individual overlapping properties instead of entire tweens.</li>
- * </ol>
- * </li>
- *
- * <li><b> ALL_ONSTART (4):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> All tweens of the same target (regardless of timing or overlapping properties).</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Very good</li>
- * <li><b>Good for:</b> When you want a tween to take priority and wipe out all other tweens of the
- * same target even if they start later. This mode is rarely used.</li>
- * </ol>
- * </li>
- *
- * <li><b> PREEXISTING (5):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> Only the tweens of the same target that were created before this tween was created
- * (regardless of timing or overlapping properties). Virtually identical to <code>ALL_IMMEDIATE</code>
- * except that <code>PREEXISTING</code> doesn't run its overwriting routines until it renders for the
- * first time, meaning that if it has a delay, other tweens won't be overwritten until the delay expires.</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Very good</li>
- * <li><b>Good for:</b> When the order in which your code runs plays a critical role, like when tweens
- * that you create later should always take precidence over previously created ones
- * regardless of when they're scheduled to run. If <code>ALL_IMMEDIATE</code> is great except
- * that you want to wait on overwriting until the tween begins, <code>PREEXISTING</code> is perfect.</li>
- * </ol>
- * </li>
- * </ul>
- *
- * With the exception of <code>ALL_IMMEDIATE</code> (which performs overwriting immediatly when the tween is created),
- * all overwriting occurs when a tween renders for the first time. So if your tween has a delay of 1 second,
- * it will not overwrite any tweens until that point. <br /><br />
- *
- * You can define a default overwriting mode for all tweens using the <code>OverwriteManager.init()</code> method, like:<br /><br /><code>
- *
- * OverwriteManager.init(OverwriteManager.AUTO);<br /><br /></code>
- *
- * If you want to override the default mode in a particular tween, just use the <code>overwrite</code> special
- * property. You can use the static constant or the corresponding number. The following two lines produce
- * the same results:<br /><br /><code>
- *
- * TweenMax.to(mc, 1, {x:100, overwrite:OverwriteManager.PREXISTING});<br />
- * TweenMax.to(mc, 1, {x:100, overwrite:5});<br /><br /></code>
- *
- * OverwriteManager is a separate, optional class for TweenLite primarily because of file size concerns.
- * Without initting OverwriteManager, TweenLite can only recognize modes 0 and 1 (<code>NONE</code> and <code>ALL_IMMEDIATE</code>).
- * However, TweenMax, TimelineLite, and TimelineMax automatically init() OverwriteManager in <code>AUTO</code> mode
- * unless you have already initted OverwriteManager manually. You do not need to take any additional steps
- * to use AUTO mode if you're using any of those classes somewhere in your project. Keep in mind too that setting
- * the default OverwriteManager mode will affect TweenLite and TweenMax tweens.<br /><br />
- *
- *
- * <b>EXAMPLES:</b><br /><br />
- *
- * To start OverwriteManager in <code>AUTO</code> mode (the default) and then do a simple TweenLite tween, simply do:<br /><br /><code>
- *
- * import com.greensock.OverwriteManager;<br />
- * import com.greensock.TweenLite;<br /><br />
- *
- * OverwriteManager.init(OverwriteManager.AUTO);<br />
- * TweenLite.to(mc, 2, {x:300});<br /><br /></code>
- *
- * You can also define overwrite behavior in individual tweens, like so:<br /><br /><code>
- *
- * import com.greensock.OverwriteManager;<br />
- * import com.greensock.TweenLite;<br /><br />
- *
- * OverwriteManager.init(2);<br />
- * TweenLite.to(mc, 2, {x:"300", y:"100"});<br />
- * TweenLite.to(mc, 1, {alpha:0.5, overwrite:1}); //or use the constant OverwriteManager.ALL_IMMEDIATE<br />
- * TweenLite.to(mc, 3, {x:200, rotation:30, overwrite:2}); //or use the constant OverwriteManager.AUTO<br /><br /></code>
- *
- *
- * OverwriteManager's mode can be changed anytime after init() is called, like.<br /><br /><code>
- *
- * OverwriteManager.mode = OverwriteManager.CONCURRENT;<br /><br /></code>
- *
- * <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.
- *
- * @author Jack Doyle, jack@greensock.com
- */
- public class OverwriteManager {
- /** @private **/
- public static const version:Number = 6.0;
- /** Won't overwrite any other tweens **/
- public static const NONE:int = 0;
- /** Overwrites all existing tweens of the same target immediately when the tween is created **/
- public static const ALL_IMMEDIATE:int = 1;
- /** Only overwrites individual overlapping tweening properties in other tweens of the same target. TweenMax, TimelineLite, and TimelineMax automatically init() OverwriteManager in this mode if you haven't already called OverwriteManager.init(). **/
- public static const AUTO:int = 2;
- /** Overwrites tweens of the same target that are active when the tween renders for the first time. **/
- public static const CONCURRENT:int = 3;
- /** Overwrites all tweens of the same target (regardless of overlapping properties or timing) when the tween renders for the first time as opposed to ALL_IMMEDIATE which performs overwriting immediately when the tween is created. **/
- public static const ALL_ONSTART:int = 4;
- /** Overwrites tweens of the same target that existed before this tween regardless of their start/end time or active state or overlapping properties. **/
- public static const PREEXISTING:int = 5;
- /** The default overwrite mode for all TweenLite and TweenMax instances **/
- public static var mode:int;
- /** @private **/
- public static var enabled:Boolean;
-
- /**
- * Initializes OverwriteManager and sets the default management mode. Options include:
- * <ul>
- * <li><b> NONE (0):</b>
- * <ol>
- * <li><b>When:</b> Never</li>
- * <li><b>Finds:</b> Nothing</li>
- * <li><b>Kills:</b> Nothing</li>
- * <li><b>Performance:</b> Excellent</li>
- * <li><b>Good for:</b> When you know that your tweens won't conflict and you want maximum speed.</li>
- * </ol>
- * </li>
- *
- * <li><b> ALL_IMMEDIATE (1):</b>
- * <ol>
- * <li><b>When:</b> Immediately when the tween is created.</li>
- * <li><b>Finds:</b> All tweens of the same target (regardless of timing or overlapping properties).</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Excellent</li>
- * <li><b>Good for:</b> When you want the tween to take priority over all other tweens of the
- * same target, like on button rollovers/rollouts. However, this mode is
- * bad for setting up sequences.</li>
- * </ol>
- * This is the default mode for TweenLite unless TweenMax, TimelineLite,
- * or TimelineMax are used in the SWF (in which case <code>AUTO</code> is the default mode).
- * </li>
- *
- * <li><b> AUTO (2):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> Only tweens of the same target that are active (running). Tweens that haven't started yet are immune.</li>
- * <li><b>Kills:</b> Only individual overlapping tweening properties. If all tweening properties
- * have been overwritten, the entire tween will be killed as well.</li>
- * <li><b>Performance:</b> Very good when there aren't many overlapping tweens; fair when there are.</li>
- * <li><b>Good for:</b> Virtually all situations. This mode does the best job overall of handling
- * overwriting in an intuitive way and is excellent for sequencing. </li>
- * </ol>
- * This is the default mode when TweenMax, TimelineLite, or TimelineMax is used in your swf (those classes
- * automatically init() OverwriteManager in <code>AUTO</code> mode unless you have already initted OverwriteManager manually).
- * </li>
- *
- * <li><b> CONCURRENT (3):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> Only tweens of the same target that are active (running). Tweens that haven't started yet are immune.</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Very good</li>
- * <li><b>Good for:</b> When you want the target object to only be controled by one tween at a time. Good
- * for sequencing although AUTO mode is typically better because it will only kill
- * individual overlapping properties instead of entire tweens.</li>
- * </ol>
- * </li>
- *
- * <li><b> ALL_ONSTART (4):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> All tweens of the same target (regardless of timing or overlapping properties).</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Very good</li>
- * <li><b>Good for:</b> When you want a tween to take priority and wipe out all other tweens of the
- * same target even if they start later. This mode is rarely used.</li>
- * </ol>
- * </li>
- *
- * <li><b> PREEXISTING (5):</b>
- * <ol>
- * <li><b>When:</b> The first time the tween renders (you can <code>invalidate()</code> a tween to force it
- * to re-init and run its overwriting routine again next time it renders)</li>
- * <li><b>Finds:</b> Only the tweens of the same target that were created before this tween was created
- * (regardless of timing or overlapping properties). Virtually identical to <code>ALL_IMMEDIATE</code>
- * except that <code>PREEXISTING</code> doesn't run its overwriting routines until it renders for the
- * first time, meaning that if it has a delay, other tweens won't be overwritten until the delay expires.</li>
- * <li><b>Kills:</b> Every tween found</li>
- * <li><b>Performance:</b> Very good</li>
- * <li><b>Good for:</b> When the order in which your code runs plays a critical role, like when tweens
- * that you create later should always take precidence over previously created ones
- * regardless of when they're scheduled to run. If <code>ALL_IMMEDIATE</code> is great except
- * that you want to wait on overwriting until the tween begins, <code>PREEXISTING</code> is perfect.</li>
- * </ol>
- * </li>
- * </ul>
- *
- * @param defaultMode The default mode that OverwriteManager should use.
- **/
- public static function init(defaultMode:int=2):int {
- if (TweenLite.version < 11.099994) {
- throw new Error("Warning: Your TweenLite class needs to be updated to work with OverwriteManager (or you may need to clear your ASO files). Please download and install the latest version from http://www.tweenlite.com.");
- }
- TweenLite.overwriteManager = OverwriteManager;
- mode = defaultMode;
- enabled = true;
- return mode;
- }
-
- /**
- * @private
- * @return Boolean value indicating whether or not properties may have changed on the target when overwriting occurred. 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 the new tween should be re-initted() with the changed properties.
- **/
- public static function manageOverwrites(tween:TweenLite, props:Object, targetTweens:Array, mode:uint):Boolean {
- var i:int, changed:Boolean, curTween:TweenLite;
- if (mode >= 4) {
- var l:uint = targetTweens.length;
- for (i = 0; i < l; i++) {
- curTween = targetTweens[i];
- if (curTween != tween) {
- if (curTween.setEnabled(false, false)) {
- changed = true;
- }
- } else if (mode == 5) {
- break;
- }
- }
- return changed;
- }
- var startTime:Number = tween.startTime, overlaps:Array = [], cousins:Array = [], cCount:uint = 0, oCount:uint = 0;
- i = targetTweens.length;
- while (i--) {
- curTween = targetTweens[i];
- if (curTween == tween || curTween.gc) {
- //ignore
- } else if (curTween.timeline != tween.timeline) {
- if (!getGlobalPaused(curTween)) {
- cousins[cCount++] = curTween;
- }
- } else if (curTween.startTime <= startTime && curTween.startTime + curTween.totalDuration > startTime && !getGlobalPaused(curTween)) {
- overlaps[oCount++] = curTween;
- }
- }
-
- if (cCount != 0) { //tweens that are nested in other timelines may have various offsets and timeScales so we need to translate them to a global/root one to see how they compare.
- var combinedTimeScale:Number = tween.cachedTimeScale, combinedStartTime:Number = startTime, cousin:TweenCore, cousinStartTime:Number, timeline:SimpleTimeline;
- timeline = tween.timeline;
- while (timeline) {
- combinedTimeScale *= timeline.cachedTimeScale;
- combinedStartTime += timeline.startTime;
- timeline = timeline.timeline;
- }
- startTime = combinedTimeScale * combinedStartTime;
- i = cCount;
- while (i--) {
- cousin = cousins[i];
- combinedTimeScale = cousin.cachedTimeScale;
- combinedStartTime = cousin.startTime;
- timeline = cousin.timeline;
- while (timeline) {
- combinedTimeScale *= timeline.cachedTimeScale;
- combinedStartTime += timeline.startTime;
- timeline = timeline.timeline;
- }
- cousinStartTime = combinedTimeScale * combinedStartTime;
- if (cousinStartTime <= startTime && (cousinStartTime + (cousin.totalDuration * combinedTimeScale) > startTime || cousin.cachedDuration == 0)) {
- overlaps[oCount++] = cousin;
- }
- }
- }
-
- if (oCount == 0) {
- return changed;
- }
-
- i = oCount;
- if (mode == 2) {
- while (i--) {
- curTween = overlaps[i];
- if (curTween.killVars(props)) {
- changed = true;
- }
- if (curTween.cachedPT1 == null && curTween.initted) {
- curTween.setEnabled(false, false); //if all property tweens have been overwritten, kill the tween.
- }
- }
-
- } else {
- while (i--) {
- if (TweenLite(overlaps[i]).setEnabled(false, false)) { //flags for garbage collection
- changed = true;
- }
- }
- }
- return changed;
- }
-
- /** @private **/
- public static function getGlobalPaused(tween:TweenCore):Boolean {
- while (tween) {
- if (tween.cachedPaused) {
- return true;
- }
- tween = tween.timeline;
- }
- return false;
- }
-
- }
-}
View
954 src/com/greensock/TimelineLite.as
@@ -1,954 +0,0 @@
-/**
- * VERSION: 1.2
- * DATE: 2010-03-06
- * AS3 (AS2 version is also available)
- * UPDATES AND DOCUMENTATION AT: http://www.greensock.com/timelinelite/
- **/
-package com.greensock {
- import com.greensock.core.*;
-
- import flash.utils.*;
-/**
- * TimelineLite is a lightweight, intuitive timeline class for building and managing sequences of
- * TweenLite, TweenMax, TimelineLite, and/or TimelineMax instances. You can think of a TimelineLite instance
- * like a virtual MovieClip timeline or a container where you place tweens (or other timelines) over the
- * course of time. You can:
- * <ul>
- * <li> build sequences easily by adding tweens with the append(), prepend(), insert(), appendMultiple(), prependMultiple(),
- * and insertMultiple() methods. Tweens can overlap as much as you want and you have complete control over where
- * they get placed on the timeline.</li>
- *
- * <li> add labels, play(), stop(), gotoAndPlay(), gotoAndStop(), restart(), and even reverse() smoothly anytime. </li>
- *
- * <li> nest timelines within timelines as deeply as you want.</li>
- *
- * <li> set the progress of the timeline using its <code>currentProgress</code> property. For example, to skip to
- * the halfway point, set <code>myTimeline.currentProgress = 0.5</code>. </li>
- *
- * <li> tween the <code>currentTime</code> or <code>currentProgress</code> property to fastforward/rewind
- * the timeline. You could even attach a slider to one of these properties to give the user the ability
- * to drag forwards/backwards through the timeline.</li>
- *
- * <li> speed up or slow down the entire timeline with its timeScale property. You can even tween
- * this property to gradually speed up or slow down.</li>
- *
- * <li> add onComplete, onStart, onUpdate, and/or onReverseComplete callbacks using the constructor's "vars" object.</li>
- *
- * <li> use the insertMultiple() or appendMultiple() methods to create complex sequences including
- * various alignment modes and staggering capabilities.</li>
- *
- * <li> base the timing on frames instead of seconds if you prefer. Please note, however, that
- * the timeline's timing mode dictates its childrens' timing mode as well. </li>
- *
- * <li> kill the tweens of a particular object with killTweensOf() or get the tweens of an object
- * with getTweensOf() or get all the tweens/timelines in the timeline with getChildren()</li>
- *
- * <li> If you need even more features like AS3 event listeners, repeat, repeatDelay, yoyo, currentLabel,
- * getLabelAfter(), getLabelBefore(), addCallback(), removeCallback(), getActive() and more, check out
- * TimelineMax which extends TimelineLite.</li>
- * </ul>
- *
- * <b>EXAMPLE:</b><br /><br /><code>
- *
- * import com.greensock.~~;<br /><br />
- *
- * //create the timeline and add an onComplete callback that will call myFunction() when the timeline completes<br />
- * var myTimeline:TimelineLite = new TimelineLite({onComplete:myFunction});<br /><br />
- *
- * //add a tween<br />
- * myTimeline.append(new TweenLite(mc, 1, {x:200, y:100}));<br /><br />
- *
- * //add another tween at the end of the timeline (makes sequencing easy)<br />
- * myTimeline.append(new TweenLite(mc, 0.5, {alpha:0}));<br /><br />
- *
- * //reverse anytime<br />
- * myTimeline.reverse();<br /><br />
- *
- * //Add a "spin" label 3-seconds into the timeline<br />
- * myTimeline.addLabel("spin", 3);<br /><br />
- *
- * //insert a rotation tween at the "spin" label (you could also define the insert point as the time instead of a label)<br />
- * myTimeline.insert(new TweenLite(mc, 2, {rotation:"360"}), "spin"); <br /><br />
- *
- * //go to the "spin" label and play the timeline from there<br />
- * myTimeline.gotoAndPlay("spin");<br /><br />
- *
- * //add a tween to the beginning of the timeline, pushing all the other existing tweens back in time<br />
- * myTimeline.prepend(new TweenMax(mc, 1, {tint:0xFF0000}));<br /><br />
- *
- * //nest another TimelineLite inside your timeline...<br />
- * var nestedTimeline:TimelineLite = new TimelineLite();<br />
- * nestedTimeline.append(new TweenLite(mc2, 1, {x:200}));<br />
- * myTimeline.append(nestedTimeline);<br /><br /></code>
- *
- *
- * insertMultiple() and appendMultiple() provide some very powerful sequencing tools, allowing you to add an Array of
- * tweens or timelines and optionally align them with SEQUENCE or START modes, and even stagger them if you want.
- * For example, to insert 3 tweens into the timeline, aligning their start times but staggering them by 0.2 seconds, <br /><br /><code>
- *
- * myTimeline.insertMultiple([new TweenLite(mc, 1, {y:"100"}),
- * new TweenLite(mc2, 1, {x:20}),
- * new TweenLite(mc3, 1, {alpha:0.5})],
- * 0,
- * TweenAlign.START,
- * 0.2);</code><br /><br />
- *
- * You can use the constructor's "vars" object to do virtually all the setup too, like this sequence:<br /><br /><code>
- *
- * var myTimeline:TimelineLite = new TimelineLite({tweens:[new TweenLite(mc1, 1, {y:"100"}), TweenMax.to(mc2, 1, {tint:0xFF0000})], align:TweenAlign.SEQUENCE, onComplete:myFunction});</code><br /><br />
- *
- * If that confuses you, don't worry. Just use the append(), insert(), and prepend() methods to build your
- * sequence. But power users will likely appreciate the quick, compact way they can set up sequences now. <br /><br />
- *
- *
- * <b>NOTES:</b>
- * <ul>
- * <li> TimelineLite automatically inits the OverwriteManager class to prevent unexpected overwriting behavior in sequences.
- * The default mode is <code>AUTO</code>, but you can set it to whatever you want with <code>OverwriteManager.init()</code>
- * (see <a href="http://www.greensock.com/overwritemanager/">http://www.greensock.com/overwritemanager/</a>)</li>
- * <li> TimelineLite adds about 2.5k to your SWF (3.3kb including OverwriteManager).</li>
- * </ul>
- *
- * <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.
- *
- * @author Jack Doyle, jack@greensock.com
- **/
- public class TimelineLite extends SimpleTimeline {
- /** @private **/
- public static const version:Number = 1.2;
- /** @private **/
- private static var _overwriteMode:int = (OverwriteManager.enabled) ? OverwriteManager.mode : OverwriteManager.init(2); //Ensures that TweenLite instances don't overwrite each other before being put into the timeline/sequence.
- /** @private **/
- protected var _labels:Object;
- /** @private Just stores the first and last tweens when the timeline is disabled (enabled=false). We do this in an Array in order to avoid circular references which can cause garbage collection issues (timeline referencing TweenCore, and TweenCore referencing timeline) **/
- protected var _endCaps:Array;
-
- /**
- * Constructor. <br /><br />
- *
- * <b>SPECIAL PROPERTIES</b><br />
- * The following special properties may be passed in via the constructor's vars parameter, like
- * <code>new TimelineLite({paused:true, onComplete:myFunction})</code>
- *
- * <ul>
- * <li><b> delay : Number</b> Amount of delay in seconds (or frames for frames-based timelines) before the timeline should begin.</li>
- *
- * <li><b> paused : Boolean</b> Sets the initial paused state of the timeline (by default, timelines automatically begin playing immediately)</li>
- *
- * <li><b> useFrames : Boolean</b> If useFrames is set to true, the timeline's timing mode will be based on frames.
- * Otherwise, it will be based on seconds/time. NOTE: a TimelineLite's timing mode is
- * always determined by its parent timeline. </li>
- *
- * <li><b> reversed : Boolean</b> If true, the timeline will be reversed initially. This does NOT force it to the very end and start
- * playing backwards. It simply affects the orientation of the timeline, so if reversed is set to
- * true initially, it will appear not to play because it is already at the beginning. To cause it to
- * play backwards from the end, set reversed to true and then set the <code>currentProgress</code> property to 1 immediately
- * after creating the timeline.</li>
- *
- * <li><b> tweens : Array</b> To immediately insert several tweens into the timeline, use the <code>tweens</code> special property
- * to pass in an Array of TweenLite/TweenMax/TimelineLite/TimelineMax instances. You can use this in conjunction
- * with the align and stagger special properties to set up complex sequences with minimal code.
- * These values simply get passed to the insertMultiple() method.</li>
- *
- * <li><b> align : String</b> Only used in conjunction with the <code>tweens</code> special property when multiple tweens are
- * to be inserted immediately. The value simply gets passed to the
- * <code>insertMultiple()</code> method. The default is <code>TweenAlign.NORMAL</code>. Options are:
- * <ul>
- * <li><b> TweenAlign.SEQUENCE:</b> aligns the tweens one-after-the-other in a sequence</li>
- * <li><b> TweenAlign.START:</b> aligns the start times of all of the tweens (ignores delays)</li>
- * <li><b> TweenAlign.NORMAL:</b> aligns the start times of all the tweens (honors delays)</li>
- * </ul>The <code>align</code> special property does <b>not</b> force all child tweens/timelines to maintain
- * relative positioning, so for example, if you use TweenAlign.SEQUENCE and then later change the duration
- * of one of the nested tweens, it does <b>not</b> force all subsequent timelines to change their position
- * on the timeline. The <code>align</code> special property only affects the alignment of the tweens that are
- * initially placed into the timeline through the <code>tweens</code> special property of the <code>vars</code> object.</li>
- *
- * <li><b> stagger : Number</b> Only used in conjunction with the <code>tweens</code> special property when multiple tweens are
- * to be inserted immediately. It staggers the tweens by a set amount of time (in seconds) (or
- * in frames if "useFrames" is true). For example, if the stagger value is 0.5 and the "align"
- * property is set to TweenAlign.START, the second tween will start 0.5 seconds after the first one
- * starts, then 0.5 seconds later the third one will start, etc. If the align property is
- * TweenAlign.SEQUENCE, there would be 0.5 seconds added between each tween. This value simply gets
- * passed to the insertMultiple() method. Default is 0.</li>
- *
- * <li><b> onStart : Function</b> A function that should be called when the timeline begins (the <code>currentProgress</code> won't necessarily
- * be zero when <code>onStart</code> is called. For example, if the timeline is created and then its <code>currentProgress</code>
- * property is immediately set to 0.5 or if its <code>currentTime</code> property is set to something other than zero,
- * <code>onStart</code> will still get fired because it is the first time the timeline is getting rendered.)</li>
- *
- * <li><b> onStartParams : Array</b> An Array of parameters to pass the onStart function.</li>
- *
- * <li><b> onUpdate : Function</b> A function that should be called every time the timeline's time/position is updated
- * (on every frame while the timeline is active)</li>
- *
- * <li><b> onUpdateParams : Array</b> An Array of parameters to pass the onUpdate function</li>
- *
- * <li><b> onComplete : Function</b> A function that should be called when the timeline has finished </li>
- *
- * <li><b> onCompleteParams : Array</b> An Array of parameters to pass the onComplete function</li>
- *
- * <li><b> onReverseComplete : Function</b> A function that should be called when the timeline has reached its starting point again after having been reversed </li>
- *
- * <li><b> onReverseCompleteParams : Array</b> An Array of parameters to pass the onReverseComplete functions</li>
- *
- * <li><b> autoRemoveChildren : Boolean</b> If autoRemoveChildren is set to true, as soon as child tweens/timelines complete,
- * they will automatically get killed/removed. This is normally undesireable because
- * it prevents going backwards in time (like if you want to <code>reverse()</code> or set the
- * <code>currentProgress</code> value to a lower value, etc.). It can, however, improve speed and memory
- * management. TweenLite's root timelines use <code>autoRemoveChildren:true</code>.</li>
- * </ul>
- *
- * @param vars optionally pass in special properties like <code>useFrames, onComplete, onCompleteParams, onUpdate, onUpdateParams, onStart, onStartParams, tweens, align, stagger, delay, reversed,</code> and/or <code>autoRemoveChildren</code>.
- */
- public function TimelineLite(vars:Object=null) {
- super(vars);
- _endCaps = [];
- _labels = {};
- this.autoRemoveChildren = Boolean(this.vars.autoRemoveChildren == true);
- _hasUpdate = Boolean(typeof(this.vars.onUpdate) == "function");
- if (this.vars.tweens is Array) {
- this.insertMultiple(this.vars.tweens, 0, this.vars.align || "normal", this.vars.stagger || 0);
- }
- }
-
- /**
- * @private
- * Adds a TweenLite, TweenMax, TimelineLite, or TimelineMax instance to this timeline.
- * Typically it is best to use the insert(), append(), or prepend() methods to add a tween
- * or timeline, though. addChild() should generally be avoided (it is used primarily by other
- * classes in the GreenSock tweening platform).
- *
- * @param tween TweenLite, TweenMax, TimelineLite, or TimelineMax instance
- */
- override public function addChild(tween:TweenCore):void {
- if (!tween.gc && tween.timeline) {
- tween.timeline.remove(tween, true); //removes from existing timeline so that it can be properly added to this one. Even if the timeline is this, it still needs to be removed so that it can be added in the appropriate order (required for proper rendering)
- }
- tween.timeline = this;
- if (tween.gc) {
- tween.setEnabled(true, true);
- }
- setDirtyCache(true);
-
- //now make sure it is inserted in the proper order...
-
- var first:TweenCore = _firstChild || _endCaps[0];
- var last:TweenCore = _lastChild || _endCaps[1];
-
- if (last == null) {
- first = last = tween;
- tween.nextNode = tween.prevNode = null;
- } else {
- var curTween:TweenCore = last, st:Number = tween.cachedStartTime;
- while (curTween != null && st <= curTween.cachedStartTime) {
- curTween = curTween.prevNode;
- }
- if (curTween == null) {
- first.prevNode = tween;
- tween.nextNode = first;
- tween.prevNode = null;
- first = tween;
- } else {
- if (curTween.nextNode) {
- curTween.nextNode.prevNode = tween;
- } else if (curTween == last) {
- last = tween;
- }
- tween.prevNode = curTween;
- tween.nextNode = curTween.nextNode;
- curTween.nextNode = tween;
- }
- }
-
- if (this.gc) {
- _endCaps[0] = first;
- _endCaps[1] = last;
- } else {
- _firstChild = first;
- _lastChild = last;
- }
- }
-
- /**
- * Removes a TweenLite, TweenMax, TimelineLite, or TimelineMax instance from the timeline.
- *
- * @param tween TweenLite, TweenMax, TimelineLite, or TimelineMax instance to remove
- * @param skipDisable If false (the default), the TweenLite/Max/TimelineLite/Max instance is disabled. This is primarily used internally - there's really no reason to set it to true.
- */
- override public function remove(tween:TweenCore, skipDisable:Boolean=false):void {
- if (tween.gc) {
- return; //already removed!
- } else if (!skipDisable) {
- tween.setEnabled(false, true);
- }
-
- var first:TweenCore = _firstChild || _endCaps[0];
- var last:TweenCore = _lastChild || _endCaps[1];
-
- if (tween.nextNode) {
- tween.nextNode.prevNode = tween.prevNode;
- } else if (last == tween) {
- last = tween.prevNode;
- }
- if (tween.prevNode) {
- tween.prevNode.nextNode = tween.nextNode;
- } else if (first == tween) {
- first = tween.nextNode;
- }
-
- if (this.gc) {
- _endCaps[0] = first;
- _endCaps[1] = last;
- } else {
- _firstChild = first;
- _lastChild = last;
- }
- //don't null nextNode and prevNode, otherwise the chain could break in rendering loops.
- setDirtyCache(true);
- }
-
- /**
- * Inserts a TweenLite, TweenMax, TimelineLite, or TimelineMax instance into the timeline at a specific time, frame, or label.
- * If you insert at a label that doesn't exist yet, one is created at the end of the timeline.
- *
- * @param tween TweenLite, TweenMax, TimelineLite, or TimelineMax instance to insert
- * @param timeOrLabel The time in seconds (or frames for frames-based timelines) or label at which the tween/timeline should be inserted. For example, myTimeline.insert(myTween, 3) would insert myTween 3-seconds into the timeline, and myTimeline.insert(myTween, "myLabel") would insert it at the "myLabel" label.
- */
- public function insert(tween:TweenCore, timeOrLabel:*=0):void {
- if (typeof(timeOrLabel) == "string") {
- if (!(timeOrLabel in _labels)) {
- addLabel(timeOrLabel, this.duration);
- }
- timeOrLabel = Number(_labels[timeOrLabel]);
- }
- /* Possible addition - this would avoid situations where a TimelineLite/Max is created as a class variable and then much later the children are added to it - without this line, the timeline would never start because it would finish immediately with no tweens.
- if (_firstChild == null && _endCaps[0] == null && (this.timeline == TweenLite.rootTimeline || this.timeline == TweenLite.rootFramesTimeline)) {
- this.startTime = this.timeline.cachedTime;
- }
- */
- tween.cachedStartTime = Number(timeOrLabel) + tween.delay;
- addChild(tween);
- }
-
- /**
- * Inserts a TweenLite, TweenMax, TimelineLite, or TimelineMax instance at the <strong>end</strong> of the timeline,
- * optionally offsetting its insertion point by a certain amount (to make it overlap with the end of
- * the timeline or leave a gap before its insertion point).
- * This makes it easy to build sequences by continuing to append() tweens or timelines.
- *
- * @param tween TweenLite, TweenMax, TimelineLite, or TimelineMax instance to append.
- * @param offset Amount of seconds (or frames for frames-based timelines) to offset the insertion point of the tween from the end of the timeline. For example, to append a tween 3 seconds after the end of the timeline (leaving a 3-second gap), set the offset to 3. Or to have the tween appended so that it overlaps with the last 2 seconds of the timeline, set the offset to -2. The default is 0 so that the insertion point is exactly at the end of the timeline.
- */
- public function append(tween:TweenCore, offset:Number=0):void {
- insert(tween, this.duration + offset);
- }
-
- /**
- * Inserts a TweenLite, TweenMax, TimelineLite, or TimelineMax instance at the beginning of the timeline,
- * pushing all existing tweens back in time to make room for the newly inserted one. You can optionally
- * affect the positions of labels too.
- *
- * @param tween TweenLite, TweenMax, TimelineLite, or TimelineMax instance to prepend
- * @param adjustLabels If true, all existing labels will be adjusted back in time along with the existing tweens to keep them aligned. (default is false)
- */
- public function prepend(tween:TweenCore, adjustLabels:Boolean=false):void {
- shiftChildren((tween.totalDuration / tween.cachedTimeScale) + tween.delay, adjustLabels, 0);
- insert(tween, 0);
- }
-
- /**
- * Inserts multiple tweens/timelines into the timeline at once, optionally aligning them (as a sequence for example)
- * and/or staggering the timing. This is one of the most powerful methods in TimelineLite because it accommodates
- * advanced timing effects and builds complex sequences with relatively little code.<br /><br />
- *
- * @param tweens an Array containing any or all of the following: TweenLite, TweenMax, TimelineLite, and/or TimelineMax instances
- * @param timeOrLabel time in seconds (or frame if the timeline is frames-based) or label that serves as the point of insertion. For example, the number 2 would insert the tweens beginning at 2-seconds into the timeline, or "myLabel" would ihsert them wherever "myLabel" is.
- * @param align determines how the tweens will be aligned in relation to each other before getting inserted. Options are: TweenAlign.SEQUENCE (aligns the tweens one-after-the-other in a sequence), TweenAlign.START (aligns the start times of all of the tweens (ignores delays)), and TweenAlign.NORMAL (aligns the start times of all the tweens (honors delays)). The default is NORMAL.
- * @param stagger staggers the tweens by a set amount of time (in seconds) (or in frames for frames-based timelines). For example, if the stagger value is 0.5 and the "align" property is set to TweenAlign.START, the second tween will start 0.5 seconds after the first one starts, then 0.5 seconds later the third one will start, etc. If the align property is TweenAlign.SEQUENCE, there would be 0.5 seconds added between each tween. Default is 0.
- */
- public function insertMultiple(tweens:Array, timeOrLabel:*=0, align:String="normal", stagger:Number=0):void {
- var i:int, tween:TweenCore, curTime:Number = Number(timeOrLabel) || 0, l:uint = tweens.length;
- if (typeof(timeOrLabel) == "string") {
- if (!(timeOrLabel in _labels)) {
- addLabel(timeOrLabel, this.duration);
- }
- curTime = _labels[timeOrLabel];
- }
- for (i = 0; i < l; i++) {
- tween = tweens[i] as TweenCore;
- insert(tween, curTime);
- if (align == "sequence") {
- curTime = tween.cachedStartTime + (tween.totalDuration / tween.cachedTimeScale);
- } else if (align == "start") {
- tween.cachedStartTime -= tween.delay;
- }
- curTime += stagger;
- }
- }
-
- /**
- * Appends multiple tweens/timelines at the end of the timeline at once, optionally offsetting the insertion point by a certain amount,
- * aligning them (as a sequence for example), and/or staggering their relative timing. This is one of the most powerful methods in
- * TimelineLite because it accommodates advanced timing effects and builds complex sequences with relatively little code.<br /><br />
- *
- * @param tweens an Array containing any or all of the following: TweenLite, TweenMax, TimelineLite, and/or TimelineMax instances
- * @param offset Amount of seconds (or frames for frames-based timelines) to offset the insertion point of the tweens from the end of the timeline. For example, to start appending the tweens 3 seconds after the end of the timeline (leaving a 3-second gap), set the offset to 3. Or to have the tweens appended so that the insertion point overlaps with the last 2 seconds of the timeline, set the offset to -2. The default is 0 so that the insertion point is exactly at the end of the timeline.
- * @param align determines how the tweens will be aligned in relation to each other before getting appended. Options are: TweenAlign.SEQUENCE (aligns the tweens one-after-the-other in a sequence), TweenAlign.START (aligns the start times of all of the tweens (ignores delays)), and TweenAlign.NORMAL (aligns the start times of all the tweens (honors delays)). The default is NORMAL.
- * @param stagger staggers the tweens by a set amount of time (in seconds) (or in frames for frames-based timelines). For example, if the stagger value is 0.5 and the "align" property is set to TweenAlign.START, the second tween will start 0.5 seconds after the first one starts, then 0.5 seconds later the third one will start, etc. If the align property is TweenAlign.SEQUENCE, there would be 0.5 seconds added between each tween. Default is 0.
- */
- public function appendMultiple(tweens:Array, offset:Number=0, align:String="normal", stagger:Number=0):void {
- insertMultiple(tweens, this.duration + offset, align, stagger);
- }
-
- /**
- * Prepends multiple tweens/timelines to the beginning of the timeline at once, moving all existing children back to make
- * room, and optionally aligning the new children (as a sequence for example) and/or staggering the timing.<br /><br />
- *
- * @param tweens an Array containing any or all of the following: TweenLite, TweenMax, TimelineLite, and/or TimelineMax instances
- * @param align determines how the tweens will be aligned in relation to each other before getting prepended. Options are: TweenAlign.SEQUENCE (aligns the tweens one-after-the-other in a sequence), TweenAlign.START (aligns the start times of all of the tweens (ignores delays)), and TweenAlign.NORMAL (aligns the start times of all the tweens (honors delays)). The default is NORMAL.
- * @param stagger staggers the tweens by a set amount of time (in seconds) (or in frames for frames-based timelines). For example, if the stagger value is 0.5 and the "align" property is set to TweenAlign.START, the second tween will start 0.5 seconds after the first one starts, then 0.5 seconds later the third one will start, etc. If the align property is TweenAlign.SEQUENCE, there would be 0.5 seconds added between each tween. Default is 0.
- */
- public function prependMultiple(tweens:Array, align:String="normal", stagger:Number=0, adjustLabels:Boolean=false):void {
- var tl:TimelineLite = new TimelineLite({tweens:tweens, align:align, stagger:stagger}); //dump them into a new temporary timeline initially so that we can determine the overall duration.
- shiftChildren(tl.duration, adjustLabels, 0);
- insertMultiple(tweens, 0, align, stagger);
- tl.kill();
- }
-
-
- /**
- * Adds a label to the timeline, making it easy to mark important positions/times. gotoAndStop() and gotoAndPlay()
- * allow you to skip directly to any label. This works just like timeline labels in the Flash IDE.
- *
- * @param label The name of the label
- * @param time The time in seconds (or frames for frames-based timelines) at which the label should be added. For example, myTimeline.addLabel("myLabel", 3) adds the label "myLabel" at 3 seconds into the timeline.
- */
- public function addLabel(label:String, time:Number):void {
- _labels[label] = time;
- }
-
- /**
- * Removes a label from the timeline and returns the time of that label.
- *
- * @param label The name of the label to remove
- * @return Time associated with the label that was removed
- */
- public function removeLabel(label:String):Number {
- var n:Number = _labels[label];
- delete _labels[label];
- return n;
- }
-
- /**
- * Returns the time associated with a particular label. If the label isn't found, -1 is returned.
- *
- * @param label Label name
- * @return Time associated with the label (or -1 if there is no such label)
- */
- public function getLabelTime(label:String):Number {
- return (label in _labels) ? Number(_labels[label]) : -1;
- }
-
- /** @private **/
- protected function parseTimeOrLabel(timeOrLabel:*):Number {
- if (typeof(timeOrLabel) == "string") {
- if (!(timeOrLabel in _labels)) {
- throw new Error("TimelineLite error: the " + timeOrLabel + " label was not found.");
- return 0;
- }
- return getLabelTime(String(timeOrLabel));
- }
- return Number(timeOrLabel);
- }
-
- /** Pauses the timeline (same as pause() - added stop() for consistency with Flash's MovieClip.stop() functionality) **/
- public function stop():void {
- this.paused = true;
- }
-
- /**
- * Skips to a particular time, frame, or label and plays the timeline forwards from there (unpausing it)
- *
- * @param timeOrLabel time in seconds (or frame if the timeline is frames-based) or label to skip to. For example, myTimeline.gotoAndPlay(2) will skip to 2-seconds into a timeline, and myTimeline.gotoAndPlay("myLabel") will skip to wherever "myLabel" is.
- * @param suppressEvents If true, no events or callbacks will be triggered as the "virtual playhead" moves to the new position (onComplete, onUpdate, onReverseComplete, etc. of this timeline and any of its child tweens/timelines won't be triggered, nor will any of the associated events be dispatched)
- */
- public function gotoAndPlay(timeOrLabel:*, suppressEvents:Boolean=true):void {
- setTotalTime(parseTimeOrLabel(timeOrLabel), suppressEvents);
- play();
- }
-
- /**
- * Skips to a particular time, frame, or label and stops the timeline (pausing it)
- *
- * @param timeOrLabel time in seconds (or frame if the timeline is frames-based) or label to skip to. For example, myTimeline.gotoAndStop(2) will skip to 2-seconds into a timeline, and myTimeline.gotoAndStop("myLabel") will skip to wherever "myLabel" is.
- * @param suppressEvents If true, no events or callbacks will be triggered as the "virtual playhead" moves to the new position (onComplete, onUpdate, onReverseComplete, etc. of this timeline and any of its child tweens/timelines won't be triggered, nor will any of the associated events be dispatched)
- */
- public function gotoAndStop(timeOrLabel:*, suppressEvents:Boolean=true):void {
- setTotalTime(parseTimeOrLabel(timeOrLabel), suppressEvents);
- this.paused = true;
- }
-
- /**
- * Skips to a particular time, frame, or label without changing the paused state of the timeline
- *
- * @param timeOrLabel time in seconds (or frame if the timeline is frames-based) or label to skip to. For example, myTimeline.goto(2) will skip to 2-seconds into a timeline, and myTimeline.goto("myLabel") will skip to wherever "myLabel" is.
- * @param suppressEvents If true, no events or callbacks will be triggered as the "virtual playhead" moves to the new position (onComplete, onUpdate, onReverseComplete, etc. of this timeline and any of its child tweens/timelines won't be triggered, nor will any of the associated events be dispatched)
- */
- public function goto(timeOrLabel:*, suppressEvents:Boolean=true):void {
- setTotalTime(parseTimeOrLabel(timeOrLabel), suppressEvents);
- }
-
-
- /**
- * @private
- * Renders all tweens and sub-timelines in the state they'd be at a particular time (or frame for frames-based timelines).
- *
- * @param time time in seconds (or frames for frames-based timelines) that should be rendered.
- * @param suppressEvents If true, no events or callbacks will be triggered for this render (like onComplete, onUpdate, onReverseComplete, etc.)
- * @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.
- */
- override public function renderTime(time:Number, suppressEvents:Boolean=false, force:Boolean=false):void {
- if (this.gc) {
- this.setEnabled(true, false);
- } else if (!this.active && !this.cachedPaused) {
- 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.
- }
- var totalDur:Number = (this.cacheIsDirty) ? this.totalDuration : this.cachedTotalDuration, prevTime:Number = this.cachedTime, prevStart:Number = this.cachedStartTime, prevTimeScale:Number = this.cachedTimeScale, tween:TweenCore, isComplete:Boolean, rendered:Boolean, next:TweenCore, dur:Number;
- if (time >= totalDur) {
- if (_rawPrevTime <= totalDur && _rawPrevTime != time) {
- this.cachedTotalTime = this.cachedTime = totalDur;
- forceChildrenToEnd(totalDur, suppressEvents);
- isComplete = !this.hasPausedChild();
- rendered = true;
- if (this.cachedDuration == 0 && isComplete && (time == 0 || _rawPrevTime < 0)) { //In order to accommodate zero-duration timelines, we must discern the momentum/direction of time in order to render values properly when the "playhead" goes past 0 in the forward direction or lands directly on it, and also when it moves past it in the backward direction (from a postitive time to a negative time).
- force = true;
- }
- }
-
- } else if (time <= 0) {
- if (time < 0) {
- this.active = false;
- if (this.cachedDuration == 0 && _rawPrevTime > 0) { //In order to accommodate zero-duration timelines, we must discern the momentum/direction of time in order to render values properly when the "playhead" goes past 0 in the forward direction or lands directly on it, and also when it moves past it in the backward direction (from a postitive time to a negative time).
- force = true;
- isComplete = true;
- }
- }
- if (_rawPrevTime >= 0 && _rawPrevTime != time) {
- forceChildrenToBeginning(0, suppressEvents);
- this.cachedTotalTime = 0;
- this.cachedTime = 0;
- rendered = true;
- if (this.cachedReversed) {
- isComplete = true;
- }
- }
- } else {
- this.cachedTotalTime = this.cachedTime = time;
- }
- _rawPrevTime = time;
-
- if (this.cachedTime == prevTime && !force) {
- return;
- } else if (!this.initted) {
- this.initted = true;
- }
- if (prevTime == 0 && this.vars.onStart && this.cachedTime != 0 && !suppressEvents) {
- this.vars.onStart.apply(null, this.vars.onStartParams);
- }
-
- if (rendered) {
- //already rendered
- } else if (this.cachedTime - prevTime > 0) {
- tween = _firstChild;
- while (tween) {
- next = tween.nextNode; //record it here because the value could change after rendering...
- if (tween.active || (!tween.cachedPaused && tween.cachedStartTime <= this.cachedTime && !tween.gc)) {
-
- if (!tween.cachedReversed) {
- tween.renderTime((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale, suppressEvents, false);
- } else {
- dur = (tween.cacheIsDirty) ? tween.totalDuration : tween.cachedTotalDuration;
- tween.renderTime(dur - ((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale), suppressEvents, false);
- }
-
- }
- tween = next;
- }
- } else {
- tween = _lastChild;
- while (tween) {
- next = tween.prevNode; //record it here because the value could change after rendering...
- if (tween.active || (!tween.cachedPaused && tween.cachedStartTime <= prevTime && !tween.gc)) {
-
- if (!tween.cachedReversed) {
- tween.renderTime((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale, suppressEvents, false);
- } else {
- dur = (tween.cacheIsDirty) ? tween.totalDuration : tween.cachedTotalDuration;
- tween.renderTime(dur - ((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale), suppressEvents, false);
- }
-
- }
- tween = next;
- }
- }
- if (_hasUpdate && !suppressEvents) {
- this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
- }
- if (isComplete && (prevStart == this.cachedStartTime || prevTimeScale != this.cachedTimeScale)) { //if one of the tweens that was rendered altered this timeline's startTime (like if an onComplete reversed the timeline), we shouldn't run complete() because it probably isn't complete. If it is, don't worry, because whatever call altered the startTime would have called complete() if it was necessary at the new time. The only exception is the timeScale property.
- complete(true, suppressEvents);
- }
- }
-
- /**
- * @private
- * Due to occassional floating point rounding errors in Flash, sometimes child tweens/timelines were not being
- * rendered at the very beginning (their currentProgress might be 0.000000000001 instead of 0 because when Flash
- * performed this.cachedTime - tween.startTime, floating point errors would return a value that
- * was SLIGHTLY off). This method forces them to the beginning.
- *
- * @param time Time that should be rendered (either zero or a negative number). The reason a negative number could be important is because if there are zero-duration tweens at the very beginning (startTime=0), we need a way to sense when the timeline has gone backwards BEYOND zero so that the tweens know to render their starting values instead of their ending values. If the time is exactly zero, those tweens would render their end values.
- * @param suppressEvents If true, no events or callbacks will be triggered for this render (like onComplete, onUpdate, onReverseComplete, etc.)
- */
- protected function forceChildrenToBeginning(time:Number, suppressEvents:Boolean=false):Number {
- var tween:TweenCore = _lastChild, next:TweenCore, dur:Number;
- while (tween) {
- next = tween.prevNode; //record it here because the value could change after rendering...
- if (tween.active || (!tween.cachedPaused && !tween.gc && (tween.cachedTotalTime != 0 || tween.cachedDuration == 0))) {
-
- if (time == 0 && (tween.cachedDuration != 0 || tween.cachedStartTime == 0)) {
- tween.renderTime(tween.cachedReversed ? tween.cachedTotalDuration : 0, suppressEvents, false);
- } else if (!tween.cachedReversed) {
- tween.renderTime((time - tween.cachedStartTime) * tween.cachedTimeScale, suppressEvents, false);
- } else {
- dur = (tween.cacheIsDirty) ? tween.totalDuration : tween.cachedTotalDuration;
- tween.renderTime(dur - ((time - tween.cachedStartTime) * tween.cachedTimeScale), suppressEvents, false);
- }
-
- }
- tween = next;
- }
- return time;
- }
-
- /**
- * @private
- * Due to occassional floating point rounding errors in Flash, sometimes child tweens/timelines were not being
- * fully completed (their currentProgress might be 0.999999999999998 instead of 1 because when Flash
- * performed this.cachedTime - tween.startTime, floating point errors would return a value that
- * was SLIGHTLY off). This method forces them to completion.
- *
- * @param time Time that should be rendered (either this.totalDuration or greater). The reason a greater number could be important is because if there are reversed zero-duration tweens at the very end, we need a way to sense when the timeline has gone BEYOND the end so that the tweens know to render their starting values instead of their ending values. If the time is exactly this.totalDuration, those reversed zero-duration tweens would render their end values.
- * @param suppressEvents If true, no events or callbacks will be triggered for this render (like onComplete, onUpdate, onReverseComplete, etc.)
- */
- protected function forceChildrenToEnd(time:Number, suppressEvents:Boolean=false):Number {
- var tween:TweenCore = _firstChild, next:TweenCore, dur:Number;
- while (tween) {
- next = tween.nextNode; //record it here because the value could change after rendering...
- if (tween.active || (!tween.cachedPaused && !tween.gc && (tween.cachedTotalTime != tween.cachedTotalDuration || tween.cachedDuration == 0))) {
-
- if (time == this.cachedDuration && (tween.cachedDuration != 0 || tween.cachedStartTime == this.cachedDuration)) {
- tween.renderTime(tween.cachedReversed ? 0 : tween.cachedTotalDuration, suppressEvents, false);
- } else if (!tween.cachedReversed) {
- tween.renderTime((time - tween.cachedStartTime) * tween.cachedTimeScale, suppressEvents, false);
- } else {
- dur = (tween.cacheIsDirty) ? tween.totalDuration : tween.cachedTotalDuration;
- tween.renderTime(dur - ((time - tween.cachedStartTime) * tween.cachedTimeScale), suppressEvents, false);
- }
-
- }
- tween = next;
- }
- return time;
- }
-
- /**
- * @private
- * Checks the timeline to see if it has any paused children (tweens/timelines).
- *
- * @return Indicates whether or not the timeline contains any paused children
- */
- public function hasPausedChild():Boolean {
- var tween:TweenCore = _firstChild || _endCaps[0];
- while (tween) {
- if (tween.cachedPaused || ((tween is TimelineLite) && (tween as TimelineLite).hasPausedChild())) {
- return true;
- }
- tween = tween.nextNode;
- }
- return false;
- }
-
- /**
- * Provides an easy way to get all of the tweens and/or timelines nested in this timeline (as an Array).
- *
- * @param nested determines whether or not tweens and/or timelines that are inside nested timelines should be returned. If you only want the "top level" tweens/timelines, set this to false.
- * @param tweens determines whether or not tweens (TweenLite and TweenMax instances) should be included in the results
- * @param timelines determines whether or not timelines (TimelineLite and TimelineMax instances) should be included in the results
- * @param ignoreBeforeTime All children with start times that are less than this value will be ignored.
- * @return an Array containing the child tweens/timelines.
- */
- public function getChildren(nested:Boolean=true, tweens:Boolean=true, timelines:Boolean=true, ignoreBeforeTime:Number=-9999999999):Array {
- var a:Array = [], tween:TweenCore = _firstChild || _endCaps[0], cnt:uint = 0;
- while (tween) {
- if (tween.cachedStartTime < ignoreBeforeTime) {
- //do nothing
- } else if (tween is TweenLite) {
- if (tweens) {
- a[cnt++] = tween;
- }
- } else {
- if (timelines) {
- a[cnt++] = tween;
- }
- if (nested) {
- a = a.concat(TimelineLite(tween).getChildren(true, tweens, timelines));
- }
- }
- tween = tween.nextNode;
- }
- return a;
- }
-
- /**
- * Returns the tweens of a particular object that are inside this timeline.
- *
- * @param target the target object of the tweens
- * @param nested determines whether or not tweens that are inside nested timelines should be returned. If you only want the "top level" tweens/timelines, set this to false.
- * @return an Array of TweenLite and TweenMax instances
- */
- public function getTweensOf(target:Object, nested:Boolean=true):Array {
- var tweens:Array = getChildren(nested, true, false), a:Array = [], i:int;
- var l:uint = tweens.length;
- for (i = 0; i < l; i++) {
- if (TweenLite(tweens[i]).target == target) {
- a[a.length] = tweens[i];
- }
- }
- return a;
- }
-
- /**
- * Shifts the startTime of the timeline's children by a certain amount and optionally adjusts labels too. This can be useful
- * when you want to prepend children or splice them into a certain spot, moving existing ones back to make room for the new ones.
- *
- * @param amount Number of seconds (or frames for frames-based timelines) to move each child.
- * @param adjustLabels If true, the timing of all labels will be adjusted as well.
- * @param ignoreBeforeTime All children that begin at or after the startAtTime will be affected by the shift (the default is 0, causing all children to be affected). This provides an easy way to splice children into a certain spot on the timeline, pushing only the children after that point back to make room.
- */
- public function shiftChildren(amount:Number, adjustLabels:Boolean=false, ignoreBeforeTime:Number=0):void {
- var tween:TweenCore = _firstChild || _endCaps[0];
- while (tween) {
- if (tween.cachedStartTime >= ignoreBeforeTime) {
- tween.cachedStartTime += amount;
- }
- tween = tween.nextNode;
- }
- if (adjustLabels) {
- for (var p:String in _labels) {
- if (_labels[p] >= ignoreBeforeTime) {
- _labels[p] += amount;
- }
- }
- }
- this.setDirtyCache(true);
- }
-
- /**
- * Kills tweens of a particular object.
- *
- * @param target the target object of the tweens
- * @param nested determines whether or not tweens that are inside nested timelines should be affected. If you only want the "top level" tweens/timelines to be affected, set this to false.
- */
- public function killTweensOf(target:Object, nested:Boolean=true):Boolean {
- var tweens:Array = getTweensOf(target, nested);
- var i:int = tweens.length;
- while (i--) {
- TweenLite(tweens[i]).setEnabled(false, false);
- }
- return Boolean(tweens.length > 0);
- }
-
- /** @inheritDoc **/
- override public function invalidate():void {
- var tween:TweenCore = _firstChild || _endCaps[0];
- while (tween) {
- tween.invalidate();
- tween = tween.nextNode;
- }
- }
-
- /**
- * Empties the timeline of all child tweens/timelines, or you can optionally pass an Array containing specific
- * tweens/timelines to remove. So <code>myTimeline.clear()</code> would remove all children whereas
- * <code>myTimeline.clear([tween1, tween2])</code> would only remove tween1 and tween2. You could even clear only
- * the tweens of a particular object with <code>myTimeline.clear(myTimeline.getTweensOf(myObject));</code>
- *
- * @param tweens (optional) An Array containing specific children to remove.
- */
- public function clear(tweens:Array=null):void {
- if (tweens == null) {
- tweens = getChildren(false, true, true);
- }
- var i:int = tweens.length;
- while (i--) {
- TweenCore(tweens[i]).setEnabled(false, false);
- }
- }
-
- /** @private **/
- override public function setEnabled(enabled:Boolean, ignoreTimeline:Boolean=false):Boolean {
- if (enabled == this.gc) {
- var tween:TweenCore, next:TweenCore;
-
- /*
- NOTE: To avoid circular references (TweenCore.timeline and SimpleTimeline._firstChild/_lastChild) which cause garbage collection
- problems, store the _firstChild and _lastChild in the _endCaps Array when the timeline is disabled.
- */
-
- if (enabled) {
- _firstChild = tween = _endCaps[0];
- _lastChild = _endCaps[1];
- } else {
- tween = _firstChild;
- _endCaps = [_firstChild, _lastChild];
- _firstChild = _lastChild = null;
- }
-
- while (tween) {
- tween.setEnabled(enabled, true);
- tween = tween.nextNode;
- }
- }
- return super.setEnabled(enabled, ignoreTimeline);
- }
-
-
-//---- GETTERS / SETTERS -------------------------------------------------------------------------------------------------------
-
- /**
- * Value between 0 and 1 indicating the progress of the timeline according to its duration
- * where 0 is at the beginning, 0.5 is halfway finished, and 1 is finished. <code>totalProgress</code>,
- * by contrast, describes the overall progress according to the timeline's <code>totalDuration</code>
- * which includes repeats and repeatDelays (if there are any). Since TimelineLite doesn't offer
- * "repeat" and "repeatDelay" functionality, <code>currentProgress</code> and <code>totalProgress</code> are always the same
- * but in TimelineMax, they could be different. For example, if a TimelineMax instance
- * is set to repeat once, at the end of the first cycle <code>totalProgress</code> would only be 0.5
- * whereas <code>currentProgress</code> would be 1. If you tracked both properties over the course of the
- * tween, you'd see <code>currentProgress</code> go from 0 to 1 twice (once for each cycle) in the same
- * time it takes the <code>totalProgress</code> property to go from 0 to 1 once.
- **/
- public function get currentProgress():Number {
- return this.cachedTime / this.duration;
- }
-
- public function set currentProgress(n:Number):void {
- setTotalTime(this.duration * n, false);
- }
-
- /**
- * Duration of the timeline in seconds (or frames for frames-based timelines) not including any repeats
- * or repeatDelays. "totalDuration", by contrast, does include repeats and repeatDelays but since TimelineLite
- * doesn't offer "repeat" and "repeatDelay" functionality, duration and totalDuration will always be the same.
- * In TimelineMax, however, they could be different.
- **/
- override public function get duration():Number {
- if (this.cacheIsDirty) {
- var d:Number = this.totalDuration; //just triggers recalculation
- }
- return this.cachedDuration;
- }
-
- override public function set duration(n:Number):void {
- if (this.duration != 0 && n != 0) {
- this.timeScale = this.duration / n;
- }
- }
-
- /**
- * Duration of the timeline in seconds (or frames for frames-based timelines) including any repeats
- * or repeatDelays. "duration", by contrast, does NOT include repeats and repeatDelays. Since TimelineLite
- * doesn't offer "repeat" and "repeatDelay" functionality, duration and totalDuration will always be the same.
- * In TimelineMax, however, they could be different.
- **/
- override public function get totalDuration():Number {
- if (this.cacheIsDirty) {
- var max:Number = 0, end:Number, tween:TweenCore = _firstChild || _endCaps[0], prevStart:Number = -Infinity, next:TweenCore;
- while (tween) {
- next = tween.nextNode; //record it here in case the tween changes position in the sequence...
-
- if (tween.cachedStartTime < prevStart) { //in case one of the tweens shifted out of order, it needs to be re-inserted into the correct position in the sequence
- this.addChild(tween);
- prevStart = tween.prevNode.cachedStartTime;
- } else {
- prevStart = tween.cachedStartTime;
- }
- if (tween.cachedStartTime < 0) { //children aren't allowed to have negative startTimes, so adjust here if one is found.
- max -= tween.cachedStartTime;
- this.shiftChildren(-tween.cachedStartTime, false, -9999999999);
- }
- end = tween.cachedStartTime + (tween.totalDuration / tween.cachedTimeScale);
- if (end > max) {
- max = end;
- }
-
- tween = next;
- }
- this.cachedDuration = this.cachedTotalDuration = max;
- this.cacheIsDirty = false;
- }
- return this.cachedTotalDuration;
- }
-
- override public function set totalDuration(n:Number):void {
- if (this.totalDuration != 0 && n != 0) {
- this.timeScale = this.totalDuration / n;
- }
- }
-
- /** Multiplier describing the speed of the timeline where 1 is normal speed, 0.5 is half-speed, 2 is double speed, etc. **/
- public function get timeScale():Number {
- return this.cachedTimeScale;
- }
-
- public function set timeScale(n:Number):void {
- if (n == 0) { //can't allow zero because it'll throw the math off
- n = 0.0001;
- }
- var tlTime:Number = (_pauseTime || _pauseTime == 0) ? _pauseTime : this.timeline.cachedTotalTime;
- this.cachedStartTime = tlTime - ((tlTime - this.cachedStartTime) * this.cachedTimeScale / n);
- this.cachedTimeScale = n;
- setDirtyCache(false);
- }
-
- /**
- * Indicates whether or not the timeline's timing mode is frames-based as opposed to time-based.
- * This can only be set via the vars object in the constructor, or by attaching it to a timeline with the desired
- * timing mode (a timeline's timing mode is always determined by its parent timeline)
- **/
- public function get useFrames():Boolean {
- var tl:SimpleTimeline = this.timeline;
- while (tl.timeline) {
- tl = tl.timeline;
- }
- return Boolean(tl == TweenLite.rootFramesTimeline);
- }
-
- /**
- * @private
- * Reports the totalTime of the timeline without capping the number at the totalDuration (max) and zero (minimum) which can be useful when
- * unpausing tweens/timelines. Imagine a case where a paused tween is in a timeline that has already reached the end, but then
- * the tween gets unpaused - it needs a way to place itself accurately in time AFTER what was previously the timeline's end time.
- *
- * @return The totalTime of the timeline without capping the number at the totalDuration (max) and zero (minimum)
- */
- override public function get rawTime():Number {
- if ((this.cachedTotalTime != 0 && this.cachedTotalTime != this.cachedTotalDuration)) { //note: don't use this.totalDuration because if other tweens get unpaused before this one, the totalDuration could change.
- return this.cachedTotalTime;
- } else {
- return (this.timeline.rawTime - this.cachedStartTime) * this.cachedTimeScale;
- }
- }
-
-
- }
-}
View
837 src/com/greensock/TimelineMax.as
@@ -1,837 +0,0 @@
-/**
- * VERSION: 1.2
- * DATE: 2010-03-06
- * AS3 (AS2 version is also available)
- * UPDATES AND DOCUMENTATION AT: http://www.greensock.com/timelinemax/
- **/
-package com.greensock {
- import com.greensock.core.*;
- import com.greensock.events.TweenEvent;
-
- import flash.events.*;
- import flash.utils.*;
-/**
- * TimelineMax extends TimelineLite, offering exactly the same functionality plus useful
- * (but non-essential) features like AS3 event dispatching, repeat, repeatDelay, yoyo,
- * currentLabel, addCallback(), removeCallback(), tweenTo(), getLabelAfter(), getLabelBefore(),
- * and getActive() (and probably more in the future). It is the ultimate sequencing tool.
- * Think of a TimelineMax instance like a virtual MovieClip timeline or a container where
- * you place tweens (or other timelines) over the course of time. You can:
- *
- * <ul>
- * <li> build sequences easily by adding tweens with the append(), prepend(), insert(), appendMultiple(),
- * prependMultiple(), and insertMultiple() methods. Tweens can overlap as much as you want and you have
- * complete control over where they get placed on the timeline.</li>
- *
- * <li> add labels, play(), stop(), gotoAndPlay(), gotoAndStop(), restart(), tweenTo() and even reverse()! </li>
- *
- * <li> nest timelines within timelines as deeply as you want.</li>
- *
- * <li> set the progress of the timeline using its <code>currentProgress</code> property. For example, to skip to
- * the halfway point, set <code>myTimeline.currentProgress = 0.5</code>.</li>
- *
- * <li> tween the <code>currentTime</code>, <code>totalTime</code>, <code>currentProgress</code>, or <code>totalProgress</code>
- * property to fastforward/rewind the timeline. You could
- * even attach a slider to one of these properties to give the user the ability to drag
- * forwards/backwards through the whole timeline.</li>
- *
- * <li> add onStart, onUpdate, onComplete, onReverseComplete, and/or onRepeat callbacks using the
- * constructor's <code>vars</code> object.</li>
- *
- * <li> speed up or slow down the entire timeline with its <code>timeScale</code> property. You can even tween
- * this property to gradually speed up or slow down the timeline.</li>
- *
- * <li> use the insertMultiple(), appendMultiple(), or prependMultiple() methods to create
- * complex sequences including various alignment modes and staggering capabilities.
- * Works great in conjunction with TweenMax.allTo() too. </li>
- *
- * <li> base the timing on frames instead of seconds if you prefer. Please note, however, that
- * the timeline's timing mode dictates its childrens' timing mode as well. </li>
- *
- * <li> kill the tweens of a particular object inside the timeline with killTweensOf() or get the tweens of an object
- * with getTweensOf() or get all the tweens/timelines in the timeline with getChildren()</li>
- *
- * <li> set the timeline to repeat any number of times or indefinitely. You can even set a delay
- * between each repeat cycle and/or cause the repeat cycles to yoyo, appearing to reverse
- * every other cycle. </li>
- *
- * <li> listen for START, UPDATE, REPEAT, REVERSE_COMPLETE, and COMPLETE events.</li>
- *
- * <li> get the active tweens in the timeline with getActive().</li>
- *
- * <li> add callbacks (function calls) anywhere in the timeline that call a function of your choosing when
- * the "virtual playhead" passes a particular spot.</li>
- *
- * <li> Get the <code>currentLabel</code> or find labels at various positions in the timeline
- * using getLabelAfter() and getLabelBefore()</li>
- * </ul>
- *
- * <b>EXAMPLE:</b><br /><br /><code>
- *
- * import com.greensock.~~;<br /><br />
- *
- * //create the timeline and add an onComplete call to myFunction when the timeline completes<br />
- * var myTimeline:TimelineMax = new TimelineMax({onComplete:myFunction});<br /><br />
- *
- * //add a tween<br />
- * myTimeline.append(new TweenLite(mc, 1, {x:200, y:100}));<br /><br />
- *
- * //add another tween at the end of the timeline (makes sequencing easy)<br />
- * myTimeline.append(new TweenLite(mc, 0.5, {alpha:0}));<br /><br />
- *
- * //repeat the entire timeline twice<br />
- * myTimeline.repeat = 2;<br /><br />
- *
- * //delay the repeat by 0.5 seconds each time.<br />
- * myTimeline.repeatDelay = 0.5;<br /><br />
- *
- * //pause the timeline (stop() works too)<br />
- * myTimeline.pause();<br /><br />
- *
- * //reverse it anytime...<br />
- * myTimeline.reverse();<br /><br />
- *
- * //Add a "spin" label 3-seconds into the timeline.<br />
- * myTimeline.addLabel("spin", 3);<br /><br />
- *
- * //insert a rotation tween at the "spin" label (you could also define the insert point as the time instead of a label)<br />
- * myTimeline.insert(new TweenLite(mc, 2, {rotation:"360"}), "spin"); <br /><br />
- *
- * //go to the "spin" label and play the timeline from there...<br />
- * myTimeline.gotoAndPlay("spin");<br /><br />
- *
- * //call myCallbackwhen the "virtual playhead" travels past the 1.5-second point.
- * myTimeline.addCallback(myCallback, 1.5);
- *
- * //add a tween to the beginning of the timeline, pushing all the other existing tweens back in time<br />
- * myTimeline.prepend(new TweenMax(mc, 1, {tint:0xFF0000}));<br /><br />
- *
- * //nest another TimelineMax inside your timeline...<br />
- * var nestedTimeline:TimelineMax = new TimelineMax();<br />
- * nestedTimeline.append(new TweenLite(mc2, 1, {x:200}));<br />
- * myTimeline.append(nestedTimeline);<br /><br /></code>
- *
- *
- * <code>insertMultiple()</code> and <code>appendMultiple()</code> provide some very powerful sequencing tools as well,
- * allowing you to add an Array of tweens/timelines and optionally align them with <code>SEQUENCE</code> or <code>START</code>
- * modes, and even stagger them if you want. For example, to insert 3 tweens into the timeline, aligning their start times but
- * staggering them by 0.2 seconds, <br /><br /><code>
- *
- * myTimeline.insertMultiple([new TweenLite(mc, 1, {y:"100"}),
- * new TweenLite(mc2, 1, {x:120}),
- * new TweenLite(mc3, 1, {alpha:0.5})],
- * 0,
- * TweenAlign.START,
- * 0.2);</code><br /><br />
- *
- * You can use the constructor's <code>vars</code> object to do all the setup too, like:<br /><br /><code>
- *
- * var myTimeline:TimelineMax = new TimelineMax({tweens:[new TweenLite(mc1, 1, {y:"100"}), TweenMax.to(mc2, 1, {tint:0xFF0000})], align:TweenAlign.SEQUENCE, onComplete:myFunction, repeat:2, repeatDelay:1});</code><br /><br />
- *
- * If that confuses you, don't worry. Just use the <code>append()</code>, <code>insert()</code>, and <code>prepend()</code> methods to build your
- * sequence. But power users will likely appreciate the quick, compact way they can set up sequences now. <br /><br />
- *
- *
- * <b>NOTES:</b>
- * <ul>
- * <li> TimelineMax automatically inits the OverwriteManager class to prevent unexpected overwriting behavior in sequences.
- * The default mode is <code>AUTO</code>, but you can set it to whatever you want with <code>OverwriteManager.init()</code>
- * (see <a href="http://www.greensock.com/overwritemanager/">http://www.greensock.com/overwritemanager/</a>)</li>
- * <li> TimelineMax adds about 4.9k to your SWF (not including OverwriteManager).</li>
- * </ul>
- *
- * <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.
- *
- * @author Jack Doyle, jack@greensock.com
- **/
- public class TimelineMax extends TimelineLite implements IEventDispatcher {
- /** @private **/
- public static const version:Number = 1.2;
-
- /** @private **/
- protected var _repeat:int;
- /** @private **/
- protected var _repeatDelay:Number;
- /** @private **/
- protected var _cyclesComplete:uint;
- /** @private **/
- protected var _dispatcher:EventDispatcher;
- /** @private **/
- protected var _hasUpdateListener:Boolean;
-
- /**
- * Works in conjunction with the repeat property, determining the behavior of each cycle; when <code>yoyo</code> is true,
- * the timeline will go back and forth, appearing to reverse every other cycle (this has no affect on the <code>reversed</code> property though).
- * So if repeat is 2 and <code>yoyo</code> is false, it will look like: start - 1 - 2 - 3 - 1 - 2 - 3 - 1 - 2 - 3 - end.
- * But if repeat is 2 and <code>yoyo</code> is true, it will look like: start - 1 - 2 - 3 - 3 - 2 - 1 - 1 - 2 - 3 - end.
- **/
- public var yoyo:Boolean;
-
- /**
- * Constructor. <br /><br />
- *
- * <b>SPECIAL PROPERTIES</b><br />
- * The following special properties may be passed in via the constructor's vars parameter, like
- * <code>new TimelineMax({paused:true, onComplete:myFunction, repeat:2, yoyo:true})</code>
- *
- * <ul>
- * <li><b> delay : Number</b> Amount of delay in seconds (or frames for frames-based timelines) before the timeline should begin.</li>
- *
- * <li><b> useFrames : Boolean</b> If <code>useFrames</code> is set to true, the timeline's timing mode will be based on frames.
- * Otherwise, it will be based on seconds/time. NOTE: a TimelineLite's timing mode is
- * always determined by its parent timeline. </li>
- *
- * <li><b> paused : Boolean</b> Sets the initial paused state of the timeline (by default, timelines automatically begin playing immediately)</li>
- *
- * <li><b> reversed : Boolean</b> If true, the timeline will be reversed initially. This does NOT force it to the very end and start
- * playing backwards. It simply affects the orientation of the timeline, so if <code>reversed</code> is set to
- * true initially, it will appear not to play because it is already at the beginning. To cause it to
- * play backwards from the end, set reversed to true and then set the <code>currentProgress</code> property to 1 immediately
- * after creating the timeline.</li>
- *
- * <li><b> tweens : Array</b> To immediately insert several tweens into the timeline, use the <code>tweens</code> special property
- * to pass in an Array of TweenLite/TweenMax/TimelineLite/TimelineMax instances. You can use this in conjunction
- * with the <code>align</code> and <code>stagger</code> special properties to set up complex sequences with minimal code.
- * These values simply get passed to the <code>insertMultiple()</code> method.</li>
- *
- * <li><b> align : String</b> Only used in conjunction with the <code>tweens</code> special property when multiple tweens are
- * to be inserted immediately through the constructor. The value simply gets passed to the
- * <code>insertMultiple()</code> method. The default is <code>TweenAlign.NORMAL</code>. Options are:
- * <ul>
- * <li><b> TweenAlign.SEQUENCE:</b> aligns the tweens one-after-the-other in a sequence</li>
- * <li><b> TweenAlign.START:</b> aligns the start times of all of the tweens (ignores delays)</li>
- * <li><b> TweenAlign.NORMAL:</b> aligns the start times of all the tweens (honors delays)</li>
- * </ul>The <code>align</code> special property does <b>not</b> force all child tweens/timelines to maintain
- * relative positioning, so for example, if you use TweenAlign.SEQUENCE and then later change the duration
- * of one of the nested tweens, it does <b>not</b> force all subsequent timelines to change their position
- * on the timeline. The <code>align</code> special property only affects the alignment of the tweens that are
- * initially placed into the timeline through the <code>tweens</code> special property of the <code>vars</code> object.</li>
- *
- * <li><b> stagger : Number</b> Only used in conjunction with the <code>tweens</code> special property when multiple tweens are
- * to be inserted immediately. It staggers the tweens by a set amount of time (in seconds) (or
- * in frames if <code>useFrames</code> is true). For example, if the stagger value is 0.5 and the <code>align</code>
- * property is set to <code>TweenAlign.START</code>, the second tween will start 0.5 seconds after the first one
- * starts, then 0.5 seconds later the third one will start, etc. If the align property is
- * <code>TweenAlign.SEQUENCE</code>, there would be 0.5 seconds added between each tween. This value simply gets
- * passed to the <code>insertMultiple()</code> method. Default is 0.</li>
- *
- * <li><b> onStart : Function</b> A function that should be called when the timeline begins (the <code>currentProgress</code> won't necessarily
- * be zero when onStart is called. For example, if the timeline is created and then its <code>currentProgress</code>
- * property is immediately set to 0.5 or if its <code>currentTime</code> property is set to something other than zero,
- * onStart will still get fired because it is the first time the timeline is getting rendered.)</li>
- *
- * <li><b> onStartParams : Array</b> An Array of parameters to pass the onStart function.</li>
- *
- * <li><b> onUpdate : Function</b> A function that should be called every time the timeline's time/position is updated
- * (on every frame while the timeline is active)</li>
- *
- * <li><b> onUpdateParams : Array</b> An Array of parameters to pass the onUpdate function</li>
- *
- * <li><b> onComplete : Function</b> A function that should be called when the timeline has finished </li>
- *
- * <li><b> onCompleteParams : Array</b> An Array of parameters to pass the onComplete function</li>
- *
- * <li><b> onReverseComplete : Function</b> A function that should be called when the timeline has reached its starting point again after having been reversed </li>
- *
- * <li><b> onReverseCompleteParams : Array</b> An Array of parameters to pass the onReverseComplete functions</li>
- *
- * <li><b> onRepeat : Function</b> A function that should be called every time the timeline repeats </li>
- *
- * <li><b> onRepeatParams : Array</b> An Array of parameters to pass the onRepeat function</li>
- *
- * <li><b> autoRemoveChildren : Boolean</b> If autoRemoveChildren is set to true, as soon as child tweens/timelines complete,
- * they will automatically get killed/removed. This is normally undesireable because
- * it prevents going backwards in time (like if you want to reverse() or set the
- * <code>currentProgress</code> value to a lower value, etc.). It can, however, improve speed and memory
- * management. TweenLite's root timelines use <code>autoRemoveChildren:true</code>.</li>
- *
- * <li><b> repeat : int</b> Number of times that the timeline should repeat. To repeat indefinitely, use -1.</li>
- *
- * <li><b> repeatDelay : Number</b> Amount of time in seconds (or frames for frames-based timelines) between repeats.</li>
- *
- * <li><b> yoyo : Boolean</b> Works in conjunction with the repeat property, determining the behavior of each
- * cycle. When <code>yoyo</code> is true, the timeline will go back and forth, appearing to reverse
- * every other cycle (this has no affect on the <code>reversed</code> 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. But
- * if repeat is 2 and yoyo is true, it will look like: start - 1 - 2 - 3 - 3 - 2 - 1 - 1 - 2 - 3 - end. </li>
- *
- * <li><b> onStartListener : Function</b> A function to which the TimelineMax instance should dispatch a TweenEvent when it begins.
- * This is the same as doing <code>myTimeline.addEventListener(TweenEvent.START, myFunction);</code></li>
- *
- * <li><b> onUpdateListener : Function</b> A function to which the TimelineMax instance should dispatch a TweenEvent every time it
- * updates values. This is the same as doing <code>myTimeline.addEventListener(TweenEvent.UPDATE, myFunction);</code></li>
- *
- * <li><b> onCompleteListener : Function</b> A function to which the TimelineMax instance should dispatch a TweenEvent when it completes.
- * This is the same as doing <code>myTimeline.addEventListener(TweenEvent.COMPLETE, myFunction);</code></li>
- * </ul>
- *
- * @param vars optionally pass in special properties like useFrames, onComplete, onCompleteParams, onUpdate, onUpdateParams, onStart, onStartParams, tweens, align, stagger, delay, autoRemoveChildren, onCompleteListener, onStartListener, onUpdateListener, repeat, repeatDelay, and/or yoyo.
- */
- public function TimelineMax(vars:Object=null) {
- super(vars);
- _repeat = this.vars.repeat || 0;
- _repeatDelay = this.vars.repeatDelay || 0;
- _cyclesComplete = 0;
- this.yoyo = this.vars.yoyo || false;
- this.cacheIsDirty = true;
- if (this.vars.onCompleteListener != null || this.vars.onUpdateListener != null || this.vars.onStartListener != null || this.vars.onRepeatListener != null || this.vars.onReverseCompleteListener != null) {
- initDispatcher();
- }
- }
-
- /**
- * If you want a function to be called at a particular time or label, use addCallback. When you add
- * a callback, it is technically considered a zero-duration tween, so if you getChildren() there will be
- * a tween returned for each callback. You can discern a callback from other tweens by the fact that
- * their target is a function and the duration is zero.
- *
- * @param function the function to be called
- * @param timeOrLabel the time in seconds (or frames for frames-based timelines) or label at which the callback should be inserted. For example, myTimeline.addCallback(myFunction, 3) would call myFunction() 3-seconds into the timeline, and myTimeline.addCallback(myFunction, "myLabel") would call it at the "myLabel" label.
- * @param params an Array of parameters to pass the callback
- * @return TweenLite instance
- */
- public function addCallback(callback:Function, timeOrLabel:*, params:Array=null):TweenLite {
- var cb:TweenLite = new TweenLite(callback, 0, {onComplete:callback, onCompleteParams:params, overwrite:0, immediateRender:false});
- insert(cb, timeOrLabel);
- return cb;
- }
-
- /**
- * Removes a callback from a particular time or label. If timeOrLabel is null, all callbacks of that
- * particular function are removed from the timeline.
- *
- * @param function callback function to be removed
- * @param timeOrLabel the time in seconds (or frames for frames-based timelines) or label from which the callback should be removed. For example, myTimeline.removeCallback(myFunction, 3) would remove the callback from 3-seconds into the timeline, and myTimeline.removeCallback(myFunction, "myLabel") would remove it from the "myLabel" label, and myTimeline.removeCallback(myFunction, null) would remove ALL callbacks of that function regardless of where they are on the timeline.
- * @return true if any callbacks were successfully found and removed. false otherwise.
- */
- public function removeCallback(callback:Function, timeOrLabel:*=null):Boolean {
- if (timeOrLabel == null) {
- return killTweensOf(callback, false);
- } else {
- if (typeof(timeOrLabel) == "string") {
- if (!(timeOrLabel in _labels)) {
- return false;
- }
- timeOrLabel = _labels[timeOrLabel];
- }
- var a:Array = getTweensOf(callback, false), success:Boolean;
- var i:int = a.length;
- while (i--) {
- if (a[i].cachedStartTime == timeOrLabel) {
- remove(a[i] as TweenCore);
- success = true;
- }
- }
- return success;
- }
- }
-
- /**
- * Creates a linear tween that essentially scrubs the playhead to a particular time or label and then stops. For
- * example, to make the TimelineMax play to the "myLabel2" label, simply do: <br /><br /><code>
- *
- * myTimeline.tweenTo("myLabel2"); <br /><br /></code>
- *
- * If you want advanced control over the tween, like adding an onComplete or changing the ease or adding a delay,
- * just pass in a vars object with the appropriate properties. For example, to tween to the 5-second point on the
- * timeline and then call a function named <code>myFunction</code> and pass in a parameter that's references this
- * TimelineMax and use a Strong.easeOut ease, you'd do: <br /><br /><code>
- *
- * myTimeline.tweenTo(5, {onComplete:myFunction, onCompleteParams:[myTimeline], ease:Strong.easeOut});<br /><br /></code>
- *
- * Remember, this method simply creates a TweenLite instance that tweens the <code>currentTime</code> property of your timeline.
- * So you can store a reference to that tween if you want, and you can kill() it anytime. Also note that <code>tweenTo()</code>
- * does <b>NOT</b> affect the timeline's <code>reversed</code> property. So if your timeline is oriented normally
- * (not reversed) and you tween to a time/label that precedes the current time, it will appear to go backwards
- * but the <code>reversed</code> property will <b>not</b> change to <code>true</code>. Also note that <code>tweenTo()</code>
- * pauses the timeline immediately before tweening its <code>currentTime</code> property, and it stays paused after the tween completes.
- * If you need to resume playback, you could always use an onComplete to call the <code>resume()</code> method.<br /><br />
- *
- * If you plan to sequence multiple playhead tweens one-after-the-other, it is typically better to use
- * <code>tweenFromTo()</code> so that you can define the starting point and ending point, allowing the
- * duration to be accurately determined immediately.
- *
- * @see #tweenFromTo()
- * @param timeOrLabel The destination time in seconds (or frame if the timeline is frames-based) or label to which the timeline should play. For example, myTimeline.tweenTo(5) would play from wherever the timeline is currently to the 5-second point whereas myTimeline.tweenTo("myLabel") would play to wherever "myLabel" is on the timeline.
- * @param vars An optional vars object that will be passed to the TweenLite instance. This allows you to define an onComplete, ease, delay, or any other TweenLite special property. onInit is the only special property that is not available (tweenTo() sets it internally)
- * @return TweenLite instance that handles tweening the timeline to the desired time/label.
- */
- public function tweenTo(timeOrLabel:*, vars:Object=null):TweenLite {
- var varsCopy:Object = {ease:easeNone, overwrite:2, useFrames:this.useFrames, immediateRender:false};
- for (var p:String in vars) {
- varsCopy[p] = vars[p];
- }
- varsCopy.onInit = onInitTweenTo;
- varsCopy.onInitParams = [null, this, NaN];
- varsCopy.currentTime = parseTimeOrLabel(timeOrLabel);
- var tl:TweenLite = new TweenLite(this, Math.abs(Number(varsCopy.currentTime) - this.cachedTime) / this.cachedTimeScale || 0.001, varsCopy);
- tl.vars.onInitParams[0] = tl;
- return tl;
- }
-
- /**
- * Creates a linear tween that essentially scrubs the playhead from a particular time or label to another
- * time or label and then stops. If you plan to sequence multiple playhead tweens one-after-the-other,
- * <code>tweenFromTo()</code> is better to use than <code>tweenTo()</code> because it allows the duration
- * to be determined immediately, ensuring that subsequent tweens that are appended to a sequence are
- * positioned appropriately. For example, to make the TimelineMax play from the label "myLabel1" to the "myLabel2"
- * label, and then from "myLabel2" back to the beginning (a time of 0), simply do: <br /><br /><code>
- *
- * var playheadTweens:TimelineMax = new TimelineMax(); <br />
- * playheadTweens.append( myTimeline.tweenFromTo("myLabel1", "myLabel2") );<br />
- * playheadTweens.append( myTimeline.tweenFromTo("myLabel2", 0); <br /><br /></code>
- *
- * If you want advanced control over the tween, like adding an onComplete or changing the ease or adding a delay,
- * just pass in a vars object with the appropriate properties. For example, to tween from the start (0) to the
- * 5-second point on the timeline and then call a function named <code>myFunction</code> and pass in a parameter
- * that's references this TimelineMax and use a Strong.easeOut ease, you'd do: <br /><br /><code>
- *
- * myTimeline.tweenFromTo(0, 5, {onComplete:myFunction, onCompleteParams:[myTimeline], ease:Strong.easeOut});<br /><br /></code>
- *
- * Remember, this method simply creates a TweenLite instance that tweens the <code>currentTime</code> property of your timeline.
- * So you can store a reference to that tween if you want, and you can <code>kill()</code> it anytime. Also note that <code>tweenFromTo()</code>
- * does <b>NOT</b> affect the timeline's <code>reversed</code> property. So if your timeline is oriented normally
- * (not reversed) and you tween to a time/label that precedes the current time, it will appear to go backwards
- * but the <code>reversed</code> property will <b>not</b> change to <code>true</code>. Also note that <code>tweenFromTo()</code>
- * pauses the timeline immediately before tweening its <code>currentTime</code> property, and it stays paused after the tween completes.
- * If you need to resume playback, you could always use an onComplete to call the <code>resume()</code> method.
- *
- * @see #tweenTo()
- * @param fromTimeOrLabel The beginning time in seconds (or frame if the timeline is frames-based) or label from which the timeline should play. For example, <code>myTimeline.tweenTo(0, 5)</code> would play from 0 (the beginning) to the 5-second point whereas <code>myTimeline.tweenFromTo("myLabel1", "myLabel2")</code> would play from "myLabel1" to "myLabel2".
- * @param toTimeOrLabel The destination time in seconds (or frame if the timeline is frames-based) or label to which the timeline should play. For example, <code>myTimeline.tweenTo(0, 5)</code> would play from 0 (the beginning) to the 5-second point whereas <code>myTimeline.tweenFromTo("myLabel1", "myLabel2")</code> would play from "myLabel1" to "myLabel2".
- * @param vars An optional vars object that will be passed to the TweenLite instance. This allows you to define an onComplete, ease, delay, or any other TweenLite special property. onInit is the only special property that is not available (<code>tweenFromTo()</code> sets it internally)
- * @return TweenLite instance that handles tweening the timeline between the desired times/labels.
- */
- public function tweenFromTo(fromTimeOrLabel:*, toTimeOrLabel:*, vars:Object=null):TweenLite {
- var tl:TweenLite = tweenTo(toTimeOrLabel, vars);
- tl.vars.onInitParams[2] = parseTimeOrLabel(fromTimeOrLabel);
- tl.duration = Math.abs(Number(tl.vars.currentTime) - tl.vars.onInitParams[2]);
- return tl;
- }
-
- /** @private **/
- private static function onInitTweenTo(tween:TweenLite, timeline:TimelineMax, fromTime:Number):void {
- timeline.paused = true;
- if (!isNaN(fromTime)) {
- timeline.currentTime = fromTime;
- }
- tween.duration = Math.abs(Number(tween.vars.currentTime) - timeline.currentTime);
- }
-
- /** @private **/
- private static function easeNone(t:Number, b:Number, c:Number, d:Number):Number {
- return t / d;
- }
-
-
- /** @private **/
- override public function renderTime(time:Number, suppressEvents:Boolean=false, force:Boolean=false):void {
- if (this.gc) {
- this.setEnabled(true, false);
- } else if (!this.active && !this.cachedPaused) {
- 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.
- }
- var totalDur:Number = (this.cacheIsDirty) ? this.totalDuration : this.cachedTotalDuration, prevTime:Number = this.cachedTime, prevStart:Number = this.cachedStartTime, tween:TweenCore, isComplete:Boolean, rendered:Boolean, repeated:Boolean, next:TweenCore, dur:Number;
- if (time >= totalDur) {
- if (_rawPrevTime <= totalDur && _rawPrevTime != time) {
- if (!this.cachedReversed && this.yoyo && _repeat % 2 != 0) {
- forceChildrenToBeginning(0, suppressEvents);
- this.cachedTime = 0;
- } else {
- forceChildrenToEnd(this.cachedDuration, suppressEvents);
- this.cachedTime = this.cachedDuration;
- }
- this.cachedTotalTime = totalDur;
- isComplete = !this.hasPausedChild();
- rendered = true;
- if (this.cachedDuration == 0 && isComplete && (time == 0 || _rawPrevTime < 0)) { //In order to accommodate zero-duration timelines, we must discern the momentum/direction of time in order to render values properly when the "playhead" goes past 0 in the forward direction or lands directly on it, and also when it moves past it in the backward direction (from a postitive time to a negative time).
- force = true;
- }
- }
-
- } else if (time <= 0) {
- if (time < 0) {
- this.active = false;
- if (this.cachedDuration == 0 && _rawPrevTime > 0) { //In order to accommodate zero-duration timelines, we must discern the momentum/direction of time in order to render values properly when the "playhead" goes past 0 in the forward direction or lands directly on it, and also when it moves past it in the backward direction (from a postitive time to a negative time).
- force = true;
- isComplete = true;
- }
- }
- if (_rawPrevTime >= 0 && _rawPrevTime != time) {
- this.cachedTotalTime = 0;
- if (!this.cachedReversed && this.yoyo && _repeat % 2 != 0) {
- forceChildrenToEnd(this.cachedDuration, suppressEvents);
- this.cachedTime = this.cachedDuration;
- } else {
- forceChildrenToBeginning(0, suppressEvents);
- this.cachedTime = 0;
- }
- rendered = true;
- if (this.cachedReversed) {
- isComplete = true;
- }
- }
- } else {
- this.cachedTotalTime = this.cachedTime = time;
- }
- _rawPrevTime = time;
-
- if (_repeat != 0) {
-
- var cycleDuration:Number = this.cachedDuration + _repeatDelay;
- if (isComplete) {
- if (this.yoyo && _repeat % 2) {
- this.cachedTime = 0;
- }
- } else if (time > 0) {
- var prevCycle:Number = _cyclesComplete;
- if (_cyclesComplete != (_cyclesComplete = int(this.cachedTotalTime / cycleDuration))) {
- repeated = true;
- }
-
- 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!)
-
- if (this.yoyo && _cyclesComplete % 2) {
- this.cachedTime = this.cachedDuration - this.cachedTime;
- } else if (this.cachedTime >= this.cachedDuration) {
- this.cachedTime = this.cachedDuration;
- }
- if (this.cachedTime < 0) {
- this.cachedTime = 0;
- }
- }
-
- if (repeated && !isComplete && (this.cachedTime != prevTime || force)) {
-
- /*
- make sure children at the end/beginning of the timeline are rendered properly. If, for example,
- a 3-second long timeline rendered at 2.9 seconds previously, and now renders at 3.2 seconds (which
- would get transated to 2.8 seconds if the timeline yoyos or 0.2 seconds if it just repeats), there
- could be a callback or a short tween that's at 2.95 or 3 seconds in which wouldn't render. So
- we need to push the timeline to the end (and/or beginning depending on its yoyo value).
- */
-
- var forward:Boolean = Boolean(!this.yoyo || (_cyclesComplete % 2 == 0));
- var prevForward:Boolean = Boolean(!this.yoyo || (prevCycle % 2 == 0));
- var wrap:Boolean = Boolean(forward == prevForward);
- if (prevCycle > _cyclesComplete) {
- prevForward = !prevForward;
- }
-
- if (prevForward) {
- prevTime = forceChildrenToEnd(this.cachedDuration, suppressEvents);
- if (wrap) {
- prevTime = forceChildrenToBeginning(0, true);
- }
- } else {
- prevTime = forceChildrenToBeginning(0, suppressEvents);
- if (wrap) {
- prevTime = forceChildrenToEnd(this.cachedDuration, true);
- }
- }
- rendered = false;
- }
-
- }
-
- if (this.cachedTime == prevTime && !force) {
- return;
- } else if (!this.initted) {
- this.initted = true;
- }
-
- if (prevTime == 0 && this.cachedTotalTime != 0 && !suppressEvents) {
- if (this.vars.onStart) {
- this.vars.onStart.apply(null, this.vars.onStartParams);
- }
- if (_dispatcher) {
- _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.START));
- }
- }
-
- if (rendered) {
- //already rendered, so ignore
- } else if (this.cachedTime - prevTime > 0) {
- tween = _firstChild;
- while (tween) {
- next = tween.nextNode; //record it here because the value could change after rendering...
- if (tween.active || (!tween.cachedPaused && tween.cachedStartTime <= this.cachedTime && !tween.gc)) {
-
- if (!tween.cachedReversed) {
- tween.renderTime((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale, suppressEvents, false);
- } else {
- dur = (tween.cacheIsDirty) ? tween.totalDuration : tween.cachedTotalDuration;
- tween.renderTime(dur - ((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale), suppressEvents, false);
- }
-
- }
-
- tween = next;
- }
- } else {
- tween = _lastChild;
- while (tween) {
- next = tween.prevNode; //record it here because the value could change after rendering...
- if (tween.active || (!tween.cachedPaused && tween.cachedStartTime <= prevTime && !tween.gc)) {
-
- if (!tween.cachedReversed) {
- tween.renderTime((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale, suppressEvents, false);
- } else {
- dur = (tween.cacheIsDirty) ? tween.totalDuration : tween.cachedTotalDuration;
- tween.renderTime(dur - ((this.cachedTime - tween.cachedStartTime) * tween.cachedTimeScale), suppressEvents, false);
- }
-
- }
-
- tween = next;
- }
- }
- if (_hasUpdate && !suppressEvents) {
- this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
- }
- if (_hasUpdateListener && !suppressEvents) {
- _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.UPDATE));
- }
- if (isComplete && prevStart == this.cachedStartTime) { //if one of the tweens that was rendered altered this timeline's startTime (like if an onComplete reversed the timeline), we shouldn't run complete() because it probably isn't complete. If it is, don't worry, because whatever call altered the startTime would have called complete() if it was necessary at the new time.
- complete(true, suppressEvents);
- } else if (repeated && !suppressEvents) {
- if (this.vars.onRepeat) {
- this.vars.onRepeat.apply(null, this.vars.onRepeatParams);
- }
- if (_dispatcher) {
- _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.REPEAT));
- }
- }
- }
-
- /**
- * Forces the timeline to completion.
- *
- * @param skipRender to skip rendering the final state of the timeline, set skipRender to true.
- * @param suppressEvents If true, no events or callbacks will be triggered for this render (like onComplete, onUpdate, onReverseComplete, etc.)
- */
- override public function complete(skipRender:Boolean=false, suppressEvents:Boolean=false):void {
- super.complete(skipRender, suppressEvents);
- if (_dispatcher && !suppressEvents) {
- if (this.cachedReversed && this.cachedTotalTime == 0 && this.cachedDuration != 0) {
- _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.REVERSE_COMPLETE));
- } else {
- _dispatcher.dispatchEvent(new TweenEvent(TweenEvent.COMPLETE));
- }
- }
- }
-
- /**
- * Returns the tweens/timelines that are currently active in the timeline.
- *
- * @param nested determines whether or not tweens and/or timelines that are inside nested timelines should be returned. If you only want the "top level" tweens/timelines, set this to false.
- * @param tweens determines whether or not tweens (TweenLite and TweenMax instances) should be included in the results
- * @param timelines determines whether or not timelines (TimelineLite and TimelineMax instances) should be included in the results
- * @return an Array of active tweens/timelines
- */
- public function getActive(nested:Boolean=true, tweens:Boolean=true, timelines:Boolean=false):Array {
- var a:Array = [], all:Array = getChildren(nested, tweens, timelines), i:int;
- var l:uint = all.length;
- var cnt:uint = 0;
- for (i = 0; i < l; i++) {
- if (TweenCore(all[i]).active) {
- a[cnt++] = all[i];
- }
- }
- return a;
- }
-
- /** @inheritDoc **/
- override public function invalidate():void {
- _repeat = this.vars.repeat || 0;
- _repeatDelay = this.vars.repeatDelay || 0;
- this.yoyo = this.vars.yoyo || false;
- if (this.vars.onCompleteListener != null || this.vars.onUpdateListener != null || this.vars.onStartListener != null || this.vars.onRepeatListener != null || this.vars.onReverseCompleteListener != null) {
- initDispatcher();
- }
- setDirtyCache(true);
- super.invalidate();
- }
-