/**
* VERSION: 11.1
* DATE: 10/18/2009
* AS2 (AS3 version is also available)
* UPDATES AND DOCUMENTATION AT: http://www.TweenMax.com
**/
import gs.*;
import gs.core.*;
import gs.plugins.*;
/**
* TweenMax extends the extremely lightweight, fast TweenLite engine, adding many useful features
* like timeScale, event listeners, setDestination(), yoyo, repeat, repeatDelay, rounding, and more. It also
* activates many extra plugins by default, making it extremely full-featured. Since TweenMax extends
* TweenLite, it can do ANYTHING TweenLite can do plus much more. The syntax is identical. With plenty
* of other tweening engines to choose from, here's why you might want to consider TweenMax:
*
*
* - SPEED - TweenMax has been highly optimized for maximum performance. See some speed comparisons yourself at
* http://blog.greensock.com/tweening-speed-test/
*
* - Feature set - In addition to tweening ANY numeric property of ANY object, TweenMax can tween filters,
* hex colors, volume, tint, frames, saturation, contrast, hue, colorization, brightness, and even do
* bezier tweening, orientToBezier, round values, jump to any point in the tween with the
currentTime
* or currentProgress property, automatically rotate in the shortest direction, plus LOTS more.
* Overwrite management is an important consideration for a tweening engine as well which is another area
* where the GreenSock Tweening Platform shines. You have options for AUTO overwriting or you can manually
* define how each tween will handle overlapping tweens of the same object.
*
* - Expandability - With its plugin architecture, you can activate as many (or as few) features as your
* project requires. Write your own plugin to handle particular special properties in custom ways. Minimize bloat, and
* maximize performance.
*
* - Sequencing, grouping, and management features - TimelineLite and TimelineMax make it surprisingly
* simple to create complex sequences or groups of tweens that you can control as a whole. play(), pause(), restart(),
* or reverse(). You can even tween a timeline's
currentTime or currentProgress property
* to fastforward or rewind the entire timeline. Add labels, gotoAndPlay(), change the timeline's timeScale, nest
* timelines within timelines, and lots more.
*
* - Ease of use - Designers and Developers alike rave about how intuitive the platform is.
*
* - Updates - Frequent updates and feature additions make the GreenSock Tweening Platform reliable and robust.
*
* - AS2 and AS3 - Most other engines are only developed for AS2 or AS3 but not both.
*
*
* SPECIAL PROPERTIES (no plugins required):
*
* Any of the following special properties can optionally be passed in through the vars object (the third parameter):
*
* - delay : Number Amount of delay before the tween should begin (in seconds).
*
* - useFrames : Boolean If useFrames is set to true, the tweens's timing mode will be based on frames.
* Otherwise, it will be based on seconds/time. NOTE: a tween's timing mode is
* always determined by its parent timeline.
*
* - ease : Function Use any standard easing equation to control the rate of change. For example,
* gs.easing.Elastic.easeOut. The Default is Regular.easeOut.
*
* - easeParams : Array An Array of extra parameters to feed the easing equation. This can be useful when
* using an ease like Elastic and want to control extra parameters like the amplitude
* and period. Most easing equations, however, don't require extra parameters so you
* won't need to pass in any easeParams.
*
* - onStart : Function A function that should be called when the tween begins.
*
* - onStartParams : Array An Array of parameters to pass the onStart function.
*
* - onStartScope: Object Defines the scope of the onStart function (what "this" refers to inside that function).
*
* - onUpdate : Function A function that should be called every time the tween's time/position is updated
* (on every frame while the timeline is active)
*
* - onUpdateParams : Array An Array of parameters to pass the onUpdate function
*
* - onUpdateScope: Object Defines the scope of the onUpdate function (what "this" refers to inside that function).
*
* - onComplete : Function A function that should be called when the tween has finished
*
* - onCompleteParams : Array An Array of parameters to pass the onComplete function
*
* - onCompleteScope: Object Defines the scope of the onComplete function (what "this" refers to inside that function).
*
* - onReverseComplete : Function A function that should be called when the tween has reached its starting point again after having been reversed.
*
* - onReverseCompleteParams : Array An Array of parameters to pass the onReverseComplete function
*
* - onReverseCompleteScope: Object Defines the scope of the onReverseComplete function (what "this" refers to inside that function).
*
* - onRepeat : Function A function that should be called every time the tween repeats
*
* - onRepeatParams : Array An Array of parameters to pass the onRepeat function
*
* - onRepeatScope: Object Defines the scope of the onRepeat function (what "this" refers to inside that function).
*
* - immediateRender : Boolean Normally when you create a tween, it begins rendering on the very next frame (when
* the Flash Player dispatches an ENTER_FRAME event) unless you specify a "delay". This
* allows you to insert tweens into timelines and perform other actions that may affect
* its timing. However, if you prefer to force the tween to render immediately when it is
* created, set immediateRender to true. Or to prevent a tween with a duration of zero from
* rendering immediately, set this to false.
*
* - paused : Boolean If true, the tween will be paused initially.
*
* - reversed : Boolean If true, the tween will be reversed initially. This does not swap the starting/ending
* values in the tween - it literally changes its orientation/direction. Imagine the playhead
* moving backwards instead of forwards. This does NOT force it to the very end and start
* playing backwards. It simply affects the orientation of the tween, 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 progress property to 1 immediately
* after creating the tween.
*
* - overwrite : Number Controls how (and if) other tweens of the same target are overwritten by this tween. There are
* several modes to choose from, and TweenMax automatically calls
OverwriteManager.init() if you haven't
* already manually dones so, which means that by default AUTO mode is used (please see
* http://blog.greensock.com/overwritemanager/
* for details and a full explanation of the various modes):
*
* - NONE (0) (or false)
*
* - ALL_IMMEDIATE (1) (or true)
*
* - AUTO (2) - this is the default mode for TweenMax.
*
* - CONCURRENT (3)
*
* - ALL_ONSTART (4)
*
* - PREEXISTING (5)
*
*
*
* - repeat : Number Number of times that the tween should repeat. To repeat indefinitely, use -1.
*
* - repeatDelay : Number Amount of time in seconds (or frames for frames-based tween) between repeats.
*
* - yoyo : Boolean Works in conjunction with the repeat property, determining the behavior of each
* cycle. When yoyo is true, the tween will go back and forth, appearing to reverse
* every other cycle (this has no affect on the
reversed 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.
*
* - startAt : Object Allows you to define the starting values for each property. Typically, TweenMax uses the current
* value (whatever it happens to be at the time the tween begins) as the start value, but startAt
* allows you to override that behavior. Simply pass an object in with whatever properties you'd like
* to set just before the tween begins. For example, if mc._x is currently 100, and you'd like to
* tween it from 0 to 500, do
TweenMax.to(mc, 2, {_x:500, startAt:{_x:0}});
*
*
* PLUGINS:
*
* There are many plugins that add capabilities through other special properties. Adding the capabilities
* is as simple as activating the plugin with a single line of code, like TweenPlugin.activate([SetSizePlugin]);
* Get information about all the plugins at http://www.TweenMax.com. The
* following plugins are activated by default in TweenMax (you can easily prevent them from activating, thus
* saving file size, by commenting out the associated activation lines towards the top of the class):
*
*
* - autoAlpha : Number - Use it instead of the alpha property to gain the additional feature of toggling
* the visible property to false when alpha reaches 0. It will also toggle visible
* to true before the tween starts if the value of autoAlpha is greater than zero.
*
* - visible : Boolean - To set a MovieClip's "_visible" property at the end of the tween, use this special property.
*
* - volume : Number - Tweens the volume of a MovieClip or Sound
*
* - tint : Number - To change a MovieClip's tint/color, set this to the hex value of the tint you'd like
* to end up at(or begin at if you're using TweenMax.from()). An example hex value would be 0xFF0000.
*
* - removeTint : Boolean - If you'd like to remove the tint that's applied to a MovieClip, pass true for this special property.
*
* - frame : Number - Use this to tween a MovieClip to a particular frame.
*
* - bezier : Array - Bezier tweening allows you to tween in a non-linear way. For example, you may want to tween
* a MovieClip's position from the origin (0,0) 500 pixels to the right (500,0) but curve downwards
* through the middle of the tween. Simply pass as many objects in the bezier array as you'd like,
* one for each "control point" (see documentation on Flash's curveTo() drawing method for more
* about how control points work). In this example, let's say the control point would be at x/y coordinates
* 250,50. Just make sure your my_mc is at coordinates 0,0 and then do:
*
TweenMax.to(my_mc, 3, {_x:500, _y:0, bezier:[{_x:250, _y:50}]});
*
* - bezierThrough : Array - Identical to bezier except that instead of passing bezier control point values, you
* pass points through which the bezier values should move. This can be more intuitive
* than using control points.
*
* - orientToBezier : Array (or Boolean) - A common effect that designers/developers want is for a MovieClip/Sprite to
* orient itself in the direction of a Bezier path (alter its rotation). orientToBezier
* makes it easy. In order to alter a rotation property accurately, TweenMax needs 4 pieces
* of information:
*
* - Position property 1 (typically "
_x")
* - Position property 2 (typically "
_y")
* - Rotational property (typically "
_rotation")
* - Number of degrees to add (optional - makes it easy to orient your MovieClip properly)
*
* The orientToBezier property should be an Array containing one Array for each set of these values.
* For maximum flexibility, you can pass in any number of arrays inside the container array, one
* for each rotational property. This can be convenient when working in 3D because you can rotate
* on multiple axis. If you're doing a standard 2D x/y tween on a bezier, you can simply pass
* in a boolean value of true and TweenMax will use a typical setup, [["_x", "_y", "_rotation", 0]].
* Hint: Don't forget the container Array (notice the double outer brackets)
*
* - hexColors : Object - Although hex colors are technically numbers, if you try to tween them conventionally,
* you'll notice that they don't tween smoothly. To tween them properly, the red, green, and
* blue components must be extracted and tweened independently. TweenMax makes it easy. To tween
* a property of your object that's a hex color to another hex color, use this special hexColors
* property of TweenMax. It must be an OBJECT with properties named the same as your object's
* hex color properties. For example, if your my_obj object has a "myHexColor" property that you'd like
* to tween to red (0xFF0000) over the course of 2 seconds, do:
* TweenMax.to(my_obj, 2, {hexColors:{myHexColor:0xFF0000}});
* You can pass in any number of hexColor properties.
*
* - shortRotation : Object - To tween the rotation property of the target object in the shortest direction, use "shortRotation"
* instead of "_rotation" as the property. For example, if
myObject._rotation is currently 170 degrees
* and you want to tween it to -170 degrees, a normal rotation tween would travel a total of 340 degrees
* in the counter-clockwise direction, but if you use shortRotation, it would travel 20 degrees in the
* clockwise direction instead.
*
* - roundProps : Array - If you'd like the inbetween values in a tween to always get rounded to the nearest integer, use the roundProps
* special property. Just pass in an Array containing the property names that you'd like rounded. For example,
* if you're tweening the _x, _y, and _alpha properties of mc and you want to round the _x and _y values (not _alpha)
* every time the tween is rendered, you'd do:
TweenMax.to(mc, 2, {_x:300, _y:200, _alpha:50, roundProps:["_x","_y"]});
*
* - blurFilter : Object - To apply a BlurFilter, pass an object with one or more of the following properties:
*
blurX, blurY, quality, remove, addFilter, index
*
* - glowFilter : Object - To apply a GlowFilter, pass an object with one or more of the following properties:
*
alpha, blurX, blurY, color, strength, quality, inner, knockout, remove, addFilter, index
*
* - colorMatrixFilter : Object - To apply a ColorMatrixFilter, pass an object with one or more of the following properties:
*
colorize, amount, contrast, brightness, saturation, hue, threshold, relative, matrix, remove, addFilter, index
*
* - dropShadowFilter : Object - To apply a DropShadowFilter, pass an object with one or more of the following properties:
*
alpha, angle, blurX, blurY, color, distance, strength, quality, remove, addFilter, index
*
* - bevelFilter : Object - To apply a BevelFilter, pass an object with one or more of the following properties:
*
angle, blurX, blurY, distance, highlightAlpha, highlightColor, shadowAlpha, shadowColor, strength, quality, remove, addFilter, index
*
*
*
* EXAMPLES:
*
* To tween the "mc" MovieClip over 5 seconds, changing the _alpha to 50, the _x to 120 using the Back.easeOut
* easing function, delay starting the whole tween by 2 seconds, and then call a function named "onFinishTween" when
* it has completed and pass in a few parameters to that function (a value of 5 and a reference to the mc),
* you'd do so like:
*
* import gs.TweenMax;
* import gs.easing.Back;
*
* TweenMax.to(mc, 5, {_alpha:50, _x:120, ease:Back.easeOut, delay:2, onComplete:onFinishTween, onCompleteParams:[5, mc]});
* function onFinishTween(param1:Number, param2:MovieClip):Void {
* trace("The tween has finished! param1 = " + param1 + ", and param2 = " + param2);
* }
*
*
* If you have a MovieClip on the stage that is already in it's end position and you just want to animate it into
* place over 5 seconds (drop it into place by changing its _y property to 100 pixels higher on the screen and
* dropping it from there), you could:
*
* import gs.TweenMax;
* import gs.easing.Elastic;
*
* TweenMax.from(mc, 5, {_y:"-100", ease:Elastic.easeOut});
*
*
* NOTES / TIPS:
*
* - Passing values as Strings will make the tween relative to the current value. For example, if you do
*
TweenMax.to(mc, 2, {_x:"-20"}); it'll move the mc._x to the left 20 pixels which is the same as doing
* TweenMax.to(mc, 2, {_x:mc._x - 20}); You could also cast it like: TweenMax.to(mc, 2, {_x:String(myVariable)});
*
* - You can kill all tweens of a particular object anytime with the
TweenMax.killTweensOf(myObject);
* function. If you want to have the tweens forced to completion, pass true as the second parameter,
* like TweenMax.killTweensOf(myObject, true);
*
* - You can kill all delayedCalls to a particular function using
TweenMax.killDelayedCallsTo(myFunction);
* This can be helpful if you want to preempt a call.
*
* - Use the TweenMax.from() method to animate things into place. For example, if you have things set up on
* the stage in the spot where they should end up, and you just want to animate them into place, you can
* pass in the beginning _x and/or _y and/or _alpha (or whatever properties you want).
*
* - If you find this class useful, please consider joining Club GreenSock which not only contributes
* to ongoing development, but also gets you bonus classes (and other benefits) that are ONLY available
* to members. Learn more at http://blog.greensock.com/club/
*
*
* Copyright 2009, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
*
* @author Jack Doyle, jack@greensock.com
*/
class gs.TweenMax extends TweenLite {
/** @private **/
public static var version:Number = 11.1;
/** @private **/
private static var _activatedPlugins:Boolean = TweenPlugin.activate([
//ACTIVATE (OR DEACTIVATE) PLUGINS HERE...
AutoAlphaPlugin, //tweens _alpha and then toggles "_visible" to false if/when _alpha is zero
EndArrayPlugin, //tweens numbers in an Array
FramePlugin, //tweens MovieClip frames
RemoveTintPlugin, //allows you to remove a tint
TintPlugin, //tweens tints
VisiblePlugin, //tweens a target's "_visible" property
VolumePlugin, //tweens the volume of a MovieClip or Sound
BevelFilterPlugin, //tweens BevelFilters
BezierPlugin, //enables bezier tweening
BezierThroughPlugin, //enables bezierThrough tweening
BlurFilterPlugin, //tweens BlurFilters
ColorMatrixFilterPlugin, //tweens ColorMatrixFilters (including hue, saturation, colorize, contrast, brightness, and threshold)
ColorTransformPlugin, //tweens advanced color properties like exposure, brightness, tintAmount, redOffset, redMultiplier, etc.
DropShadowFilterPlugin, //tweens DropShadowFilters
FrameLabelPlugin, //tweens a MovieClip to particular label
GlowFilterPlugin, //tweens GlowFilters
HexColorsPlugin, //tweens hex colors
RoundPropsPlugin, //enables the roundProps special property for rounding values (ONLY for TweenMax!)
ShortRotationPlugin, //tweens rotation values in the shortest direction
//QuaternionsPlugin, //tweens 3D Quaternions
//ScalePlugin, //Tweens both the _xscale and _yscale properties
//ScrollRectPlugin, //tweens the scrollRect property of a MovieClip
//SetSizePlugin, //tweens the width/height of components via setSize()
//TransformMatrixPlugin, //Tweens the transform.matrix property of any MovieClip
//DynamicPropsPlugin, //tweens to dynamic end values. You associate the property with a particular function that returns the target end value **Club GreenSock membership benefit**
//MotionBlurPlugin, //applies a directional blur to a MovieClip based on the velocity and angle of movement. **Club GreenSock membership benefit**
//Physics2DPlugin, //allows you to apply basic physics in 2D space, like velocity, angle, gravity, friction, acceleration, and accelerationAngle. **Club GreenSock membership benefit**
//PhysicsPropsPlugin, //allows you to apply basic physics to any property using forces like velocity, acceleration, and/or friction. **Club GreenSock membership benefit**
//TransformAroundCenterPlugin,//tweens the scale and/or rotation of MovieClips using the MovieClip's center as the registration point **Club GreenSock membership benefit**
//TransformAroundPointPlugin, //tweens the scale and/or rotation of MovieClips around a particular point (like a custom registration point) **Club GreenSock membership benefit**
{}]); //activated in static var instead of constructor because otherwise if there's a from() tween, TweenLite's constructor would get called first and initTweenVals() would run before the plugins were activated.
/** @private OverwriteManager is optional for TweenLite but it is used by default in TweenMax so we init it here (if it isn't already enabled).**/
private static var _overwriteMode:Number = (OverwriteManager.enabled) ? OverwriteManager.mode : OverwriteManager.init(2);
/** @private **/
private static var _pauseAllTime:Number;
/**
* Kills all the tweens of a particular object, optionally completing them first.
*
* @param target Object whose tweens should be immediately killed
* @param complete Indicates whether or not the tweens should be forced to completion before being killed.
*/
public static var killTweensOf:Function = TweenLite.killTweensOf;
/** @private **/
public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
/** @private **/
private var _repeat:Number;
/** @private **/
private var _repeatDelay:Number;
/** @private **/
private var _cyclesComplete:Number;
/**
* Works in conjunction with the repeat property, determining the behavior of each cycle; when yoyo is true,
* the tween will go back and forth, appearing to reverse every other cycle (this has no affect on the "reversed"
* 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.
**/
public var yoyo:Boolean;
/**
* Constructor
*
* @param target Target object whose properties this tween affects. This can be ANY object, not just a MovieClip.
* @param duration Duration in seconds (or in frames if the tween's timing mode is frames-based)
* @param vars An object containing the end values of the properties you're tweening. For example, to tween to _x=100, _y=100, you could pass {_x:100, _y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
*/
public function TweenMax(target:Object, duration:Number, vars:Object) {
super(target, duration, vars);
if (TweenLite.version < 11.1) {
trace("TweenMax error! Please update your TweenLite class or try deleting your ASO files. TweenMax requires a more recent version. Download updates at http://www.TweenMax.com.");
}
_cyclesComplete = 0;
this.yoyo = Boolean(this.vars.yoyo);
_repeat = this.vars.repeat || 0;
_repeatDelay = this.vars.repeatDelay || 0;
this.cacheIsDirty = true; //ensures that if there is any repeat, the totalDuration will get recalculated to accurately report it.
if (this.vars.timeScale != undefined && !(this.target instanceof TweenCore)) {
this.cachedTimeScale = this.vars.timeScale;
}
}
/**
* @private
* Initializes the property tweens, determining their start values and amount of change.
* Also triggers overwriting if necessary and sets the _hasUpdate variable.
*/
private function init():Void {
if (this.vars.startAt) {
this.vars.startAt.overwrite = 0;
this.vars.startAt.immediateRender = true;
var startTween:TweenMax = new TweenMax(this.target, 0, this.vars.startAt);
}
super.init();
//accommodate rounding if necessary...
if (this.vars.roundProps && TweenLite.plugins.roundProps) {
var j:Number, prop:String, multiProps:String, rp:Array = this.vars.roundProps, plugin:Object, pt:PropTween;
var i:Number = rp.length;
while (i--) {
prop = rp[i];
pt = this.cachedPT1;
while (pt) {
if (pt.name == prop) {
if (pt.isPlugin) {
pt.target.round = true;
} else {
if (plugin == undefined) {
plugin = new TweenLite.plugins.roundProps();
plugin.add(pt.target, prop, pt.start, pt.change);
_hasPlugins = true;
this.cachedPT1 = insertPropTween(plugin, "changeFactor", 0, 1, "_MULTIPLE_", true, this.cachedPT1);
} else {
plugin.add(pt.target, prop, pt.start, pt.change); //using a single plugin for rounding speeds processing
}
this.removePropTween(pt);
}
} else if (pt.isPlugin && pt.name == "_MULTIPLE_" && !pt.target.round) {
multiProps = " " + pt.target.overwriteProps.join(" ") + " ";
if (multiProps.indexOf(" " + prop + " ") != -1) {
pt.target.round = true;
}
}
pt = pt.nextNode;
}
}
}
}
/**
* @private
* Inserts a new property tween into the linked list.
*
* @param target Object whose property is being tweened
* @param property Name of the property that is being tweened (according to the property tween's target)
* @param start Starting value of the property
* @param end End value of the property (if it is a String, it will be interpreted as relative)
* @param name The name of the property that is being tweened (according to tween's target). This can be different than the "property". For example, for a bezier tween, the target could be the plugin, the property could be "changeFactor", and the name could be "x" or "_MULTIPLE_" if the plugin is managing more than one property. This aids in overwrite management.
* @param isPlugin Indicates whether or not the property tween is a plugin
* @param nextNode Next PropTween instance in the linked list. (this just helps speed things up)
* @return PropTween instance that was created/inserted
*/
private function insertPropTween(target:Object, property:String, start:Number, end:Object, name:String, isPlugin:Boolean, nextNode:PropTween):PropTween {
var pt:PropTween = new PropTween(target, property, start, (typeof(end) == "number") ? Number(end) - start : Number(end), name, isPlugin, nextNode);
if (isPlugin && name == "_MULTIPLE_") {
var i:Number = target.overwriteProps.length;
while (i--) {
propTweenLookup[target.overwriteProps[i]] = pt;
}
} else {
propTweenLookup[name] = pt;
}
return pt;
}
/**
* @private
* Removes a PropTween from the linked list
*
* @param propTween PropTween to remove
* @return Boolean value indicating whether or not properties may have changed on the target when the PropTween was disabled. For example, when a motionBlur (plugin) is disabled, it swaps out a BitmapData for the target and may alter the alpha. We need to know this in order to determine whether or not a new tween that is overwriting this one should be re-initted() with the changed properties.
*/
private function removePropTween(propTween:PropTween):Boolean {
if (propTween.nextNode) {
propTween.nextNode.prevNode = propTween.prevNode;
}
if (propTween.prevNode) {
propTween.prevNode.nextNode = propTween.nextNode;
} else if (this.cachedPT1 == propTween) {
this.cachedPT1 = propTween.nextNode;
}
if (propTween.isPlugin && propTween.target.onDisable) {
propTween.target.onDisable(); //some plugins need to be notified so they can perform cleanup tasks first
if (propTween.target.activeDisable) {
return true;
}
}
return false;
}
/** @inheritDoc **/
public function invalidate():Void {
this.yoyo = Boolean(this.vars.yoyo);
_repeat = this.vars.repeat || 0;
_repeatDelay = this.vars.repeatDelay || 0;
setDirtyCache(true);
super.invalidate();
}
/**
* @private
* Adjusts tween values on the fly. This is a work-in-progress and, when finished, will be made public.
*
* @param vars Object containing properties with the end values that should be udpated. For example, to update the destination _x value to 300 and the destination _y value to 500, pass: {_x:300, _y:500}
* @param adjustStartValues If true, the property's start value will be adjusted to make the tween appear to seamlessly/smoothly redirect without any skipping/jerking. Beware that if start values are adjusted, reversing the tween will not make it travel back to the original starting value.
*/
private function updateTo(vars:Object, adjustStartingValues:Boolean):Void {
var pt:PropTween = this.cachedPT1, curTime:Number = this.cachedTotalTime, p:String, plugin:Object, prioritize:Boolean, pluginKillVars:Object, i:Number;
if (this.initted) {
if (adjustStartingValues != true) {
this.totalTime = 0;
}
killVars(vars, false);
for (p in vars) {
if (_reservedProps[p] != undefined) {
//ignore
} else if (plugins[p] != undefined) {
plugin = new plugins[p]();
if (!plugin.onInitTween(this.target, vars[p], this)) { //if the plugin init fails, do a regular tween
this.cachedPT1 = insertPropTween(this.target, p, this.target[p], vars[p], p, false, this.cachedPT1);
} else {
pluginKillVars = {};
i = plugin.overwriteProps.length;
while (i--) {
pluginKillVars[plugin.overwriteProps[i]] = true;
}
killVars(pluginKillVars, false);
this.cachedPT1 = insertPropTween(plugin, "changeFactor", 0, 1, (plugin.overwriteProps.length == 1) ? plugin.overwriteProps[0] : "_MULTIPLE_", true, this.cachedPT1);
_hasPlugins = true;
if (plugin.priority) {
this.cachedPT1.priority = plugin.priority;
prioritize = true;
}
}
} else {
this.cachedPT1 = insertPropTween(this.target, p, this.target[p], vars[p], p, false, this.cachedPT1);
}
this.vars[p] = vars[p];
}
if (prioritize) {
onPluginEvent("onInit", this); //reorders the linked list in order of priority. Uses a static TweenPlugin method in order to minimize file size in TweenLite
}
if (adjustStartingValues == true && this.cachedTotalTime) {
adjustStartValues();
//this.totalTime = curTime;
}
} else {
for (p in vars) {
this.vars[p] = vars[p];
}
}
}
/**
* Adjusts a destination value on the fly, optionally adjusting the start values so that it appears to redirect seamlessly
* without skipping/jerking. If you plan to constantly update values, please look into using the DynamicPropsPlugin.
*
* @param property Name of the property that should be updated. For example, "_x".
* @param value The new destination value
* @param adjustStartValues If true, the property's start value will be adjusted to make the tween appear to seamlessly/smoothly redirect without any skipping/jerking. Beware that if start values are adjusted, reversing the tween will not make it travel back to the original starting value.
*/
public function setDestination(property:String, value:Object, adjustStartValues:Boolean):Void {
var vars:Object = {};
vars[property] = value;
updateTo(vars, Boolean(adjustStartValues != false));
}
/**
* @private
* Adjusts the start values in the tweens so that the current progress and end values are maintained
* which prevents "skipping" when changing destination values mid-way through the tween.
*/
private function adjustStartValues():Void {
if (this.cachedTime != 0) {
var inv:Number = 1 / (1 - this.ratio);
var pt:PropTween = this.cachedPT1, endValue:Number, i:Number;
while (pt) {
endValue = pt.start + pt.change;
if (pt.isPlugin) { //can't read the "progress" value of a plugin, but we know what it is based on this.ratio (above)
pt.change = (endValue - this.ratio) * inv;
} else {
pt.change = (endValue - pt.target[pt.property]) * inv;
}
pt.start = endValue - pt.change;
pt = pt.nextNode;
}
}
}
/**
* Allows particular properties of the tween to be killed, much like the killVars() method
* except that killProperties() accepts an Array of property names.
*
* @param names An Array of property names whose tweens should be killed immediately.
*/
public function killProperties(names:Array):Void {
var v:Object = {}, i:Number = names.length;
while (i--) {
v[names[i]] = true;
}
killVars(v);
}
/**
* @private
* Renders the tween at a particular time (or frame number for frames-based tweens).
* The time is based simply on the overall duration. For example, if a tween's duration
* is 3, renderTime(1.5) would render it at the halfway finished point.
*
* @param time time (or frame number for frames-based tweens) to render.
* @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.
*/
public function renderTime(time:Number, suppressEvents:Boolean, force:Boolean):Void {
if (!this.active && !this.cachedPaused) {
this.active = true;
}
var totalDur:Number = (this.cacheIsDirty) ? this.totalDuration : this.cachedTotalDuration, prevTime:Number = this.cachedTime, isComplete:Boolean, repeated:Boolean, setRatio:Boolean;
if (time >= totalDur) {
this.cachedTotalTime = totalDur;
this.cachedTime = this.cachedDuration;
this.ratio = 1;
isComplete = true;
if (this.cachedDuration == 0) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
if ((time == 0 || _rawPrevTime < 0) && _rawPrevTime != time) {
force = true;
}
_rawPrevTime = time;
}
} else if (time <= 0) {
if (time < 0) {
this.active = false;
if (this.cachedDuration == 0) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered.
if (_rawPrevTime > 0) {
force = true;
isComplete = true;
}
_rawPrevTime = time;
}
}
this.cachedTotalTime = this.cachedTime = this.ratio = 0;
if (this.cachedReversed && prevTime != 0) {
isComplete = true;
}
} else {
this.cachedTotalTime = this.cachedTime = time;
if (_repeat == 0) {
setRatio = true;
}
}
if (_repeat != 0) {
var cycleDuration:Number = this.cachedDuration + _repeatDelay;
if (time > 0) {
this.cachedTime = ((this.yoyo && (this.cachedTotalTime / cycleDuration) % 2 >= 1) || (!this.yoyo && !((this.cachedTotalTime / cycleDuration) % 1))) ? this.cachedDuration - (this.cachedTotalTime % cycleDuration) : this.cachedTotalTime % cycleDuration;
if (this.cachedTime >= this.cachedDuration) {
this.cachedTime = this.cachedDuration;
this.ratio = 1;
} else if (this.cachedTime <= 0) {
this.cachedTime = this.ratio = 0;
} else {
setRatio = true;
}
}
if (_cyclesComplete != Math.floor(this.cachedTotalTime / cycleDuration) && !isComplete) {
repeated = true;
_cyclesComplete = Math.floor(this.cachedTotalTime / cycleDuration);
}
}
if (prevTime == this.cachedTime && !force) {
return;
} else if (!this.initted) {
init();
}
if (setRatio) {
this.ratio = _ease(this.cachedTime, 0, 1, this.cachedDuration);
}
if (prevTime == 0 && this.vars.onStart && this.cachedTotalTime != 0 && !suppressEvents) {
this.vars.onStart.apply(this.vars.onStartScope, this.vars.onStartParams);
}
var pt:PropTween = this.cachedPT1;
while (pt) {
pt.target[pt.property] = pt.start + (this.ratio * pt.change);
pt = pt.nextNode;
}
if (_hasUpdate && !suppressEvents) {
this.vars.onUpdate.apply(this.vars.onUpdateScope, this.vars.onUpdateParams);
}
if (isComplete) {
if (_hasPlugins && this.cachedPT1) {
onPluginEvent("onComplete", this);
}
complete(true, suppressEvents);
} else if (repeated && !suppressEvents) {
if (this.vars.onRepeat) {
this.vars.onRepeat.apply(this.vars.onRepeatScope, this.vars.onRepeatParams);
}
}
}
//---- STATIC FUNCTIONS -----------------------------------------------------------------------------------------------------------
/**
* Static method for creating a TweenMax instance. This can be more intuitive for some developers
* and shields them from potential garbage collection issues that could arise when assigning a
* tween instance to a variable that persists. The following lines of code produce exactly
* the same result:
*
* var myTween:TweenMax = new TweenMax(mc, 1, {_x:100});
* TweenMax.to(mc, 1, {_x:100});
* var myTween:TweenMax = TweenMax.to(mc, 1, {_x:100});
*
* @param target Target object whose properties this tween affects. This can be ANY object, not just a MovieClip.
* @param duration Duration in seconds (or in frames if the tween's timing mode is frames-based)
* @param vars An object containing the end values of the properties you're tweening. For example, to tween to _x=100, _y=100, you could pass {_x:100, _y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
* @return TweenMax instance
*/
public static function to(target:Object, duration:Number, vars:Object):TweenMax {
return new TweenMax(target, duration, vars);
}
/**
* Static method for creating a TweenMax instance that tweens in the opposite direction
* compared to a TweenMax.to() tween. In other words, you define the START values in the
* vars object instead of the end values, and the tween will use the current values as
* the end values. This can be very useful for animating things into place on the stage
* because you can build them in their end positions and do some simple TweenMax.from()
* calls to animate them into place. NOTE: By default, immediateRender
* is true for from() tweens, meaning that they immediately render their starting state
* regardless of any delay or stagger that is specified. You can override this behavior by passing
* immediateRender:false in the vars object so that it will wait to
* render until the tween actually begins (often the desired behavior when inserting into timelines).
* To illustrate the default behavior, the following code will immediately set the _alpha of mc
* to 0 and then wait 2 seconds before tweening the _alpha back to 100 over the course
* of 1.5 seconds:
*
* TweenMax.from(mc, 1.5, {_alpha:0, delay:2});
*
* @param target Target object whose properties this tween affects. This can be ANY object, not just a MovieClip.
* @param duration Duration in seconds (or in frames if the tween's timing mode is frames-based)
* @param vars An object containing the start values of the properties you're tweening. For example, to tween from _x=100, _y=100, you could pass {_x:100, __y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
* @return TweenMax instance
*/
public static function from(target:Object, duration:Number, vars:Object):TweenMax {
vars.runBackwards = true;
if (vars.immediateRender != false) {
vars.immediateRender = true;
}
return new TweenMax(target, duration, vars);
}
/**
* Static method for creating a TweenMax instance that tweens from a particular set of
* values to another set of values, as opposed to a normal to() or from() tween which are
* based on the target's current values.
*
* @param target Target object whose properties this tween affects. This can be ANY object, not just a MovieClip.
* @param duration Duration in seconds (or in frames if the tween's timing mode is frames-based)
* @param fromVars An object containing the starting values of the properties you're tweening. For example, to tween from _x=0, _y=0, you could pass {_x:0, _y:0}.
* @param toVars An object containing the ending values of the properties you're tweening. For example, to tween to _x=100, _y=100, you could pass {_x:100, _y:100}. It can also contain special properties like "onComplete", "ease", "delay", etc.
* @return TweenMax instance
*/
public static function fromTo(target:Object, duration:Number, fromVars:Object, toVars:Object):TweenMax {
toVars.startAt = fromVars;
if (fromVars.immediateRender) {
toVars.immediateRender = true;
}
return new TweenMax(target, duration, toVars);
}
/**
* Tween multiple objects to the same end values. The "stagger" parameter
* staggers the start time of each tween. For example, you might want to have 5 MovieClips move down
* 100 pixels while fading out, and stagger the start times slightly by 0.2 seconds:
* TweenMax.allTo([mc1, mc2, mc3, mc4, mc5], 1, {_y:"100", _alpha:0}, 0.2);
*
* Note: You can easily add a group of tweens to a TimelineLite/Max instance using allTo() in conjunction with the
* insertMultipe() method of a timeline, like:
* myTimeline.insertMultiple(TweenMax.allTo([mc1, mc2, mc3], 1, {_alpha:0, _y:"100"}, 0.1));
*
* @param targets An Array of objects to tween.
* @param duration Duration (in seconds) of the tween (or in frames for frames-based tweens)
* @param vars An object containing the end values of all the properties you'd like to have tweened (or if you're using the TweenMax.allFrom() method, these variables would define the BEGINNING values).
* @param stagger Staggers the start time of each tween. For example, you might want to have 5 MovieClips move down 100 pixels while fading out, and stagger the start times slightly by 0.2 seconds, you could do: TweenMax.allTo([mc1, mc2, mc3, mc4, mc5], 1, {_y:"100", _alpha:0}, 0.2).
* @param onCompleteAll A function to call when all of the tweens have completed.
* @param onCompleteAllParams An Array of parameters to pass the onCompleteAll function when all the tweens have completed.
* @return Array of TweenMax tweens
*/
public static function allTo(targets:Array, duration:Number, vars:Object, stagger:Number, onCompleteAll:Function, onCompleteAllParams:Array, onCompleteAllScope:Object):Array {
var i:Number, varsDup:Object, p:String;
var l:Number = targets.length;
var a:Array = [];
var curDelay:Number = vars.delay || 0;
var onCompleteProxy:Function = vars.onComplete;
var onCompleteParamsProxy:Array = vars.onCompleteParams;
var onCompleteScopeProxy:Object = vars.onCompleteScope;
var lastIndex:Number = (stagger <= 0 || stagger == undefined) ? 0 : l - 1;
for (i = 0; i < l; i++) {
varsDup = {};
for (p in vars) {
varsDup[p] = vars[p];
}
varsDup.delay = curDelay;
if (i == lastIndex && onCompleteAll != undefined) {
varsDup.onComplete = function():Void {
if (onCompleteProxy != undefined) {
onCompleteProxy.apply(onCompleteScopeProxy, onCompleteParamsProxy);
}
onCompleteAll.apply(onCompleteAllScope, onCompleteAllParams);
}
}
a[a.length] = new TweenMax(targets[i], duration, varsDup);
curDelay += stagger;
}
return a;
}
/**
* Exactly the same as TweenMax.allTo(), but instead of tweening the properties from where they're
* at currently to whatever you define, this tweens them the opposite way - from where you define TO
* where ever they are when the tweens begin. This is useful when things are set up on the stage the way they should
* end up and you just want to tween them into place. NOTE: By default, immediateRender
* is true for allFrom() tweens, meaning that they immediately render their starting state
* regardless of any delay or stagger that is specified. You can override this behavior by passing
* immediateRender:false in the vars object so that each tween will wait to render until
* any delay/stagger has passed (often the desired behavior when inserting into timelines). To illustrate
* the default behavior, the following code will immediately set the _alpha of mc1,
* mc2, and mc3 to 0 and then wait 2 seconds before tweening each _alpha
* back to 100 over the course of 1.5 seconds with 0.1 seconds lapsing between the start times of each:
*
* TweenMax.allFrom([mc1, mc2, mc3], 1.5, {_alpha:0, delay:2}, 0.1);
*
* @param targets An Array of objects to tween.
* @param duration Duration (in seconds) of the tween (or in frames for frames-based tweens)
* @param vars An object containing the start values of all the properties you'd like to have tweened.
* @param stagger Staggers the start time of each tween. For example, you might want to have 5 MovieClips move down 100 pixels while fading from _alpha:0, and stagger the start times slightly by 0.2 seconds, you could do: TweenMax.allFromTo([mc1, mc2, mc3, mc4, mc5], 1, {_y:"-100", _alpha:0}, 0.2).
* @param onCompleteAll A function to call when all of the tweens have completed.
* @param onCompleteAllParams An Array of parameters to pass the onCompleteAll function when all the tweens have completed.
* @return Array of TweenMax instances
*/
public static function allFrom(targets:Array, duration:Number, vars:Object, stagger:Number, onCompleteAll:Function, onCompleteAllParams:Array, onCompleteAllScope:Object):Array {
vars.runBackwards = true;
if (vars.immediateRender != false) {
vars.immediateRender = true;
}
return allTo(targets, duration, vars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope);
}
/**
* Tweens multiple targets from a common set of starting values to a common set of ending values; exactly the same
* as TweenMax.allTo(), but adds the ability to define the starting values. NOTE: Only put starting values
* in the fromVars parameter - all special properties for the tween (like onComplete, onUpdate, delay, etc.) belong
* in the toVars parameter.
*
* @param targets An Array of objects to tween.
* @param duration Duration (in seconds) of the tween (or in frames for frames-based tweens)
* @param fromVars An object containing the starting values of all the properties you'd like to have tweened.
* @param toVars An object containing the ending values of all the properties you'd like to have tweened.
* @param stagger Staggers the start time of each tween. For example, you might want to have 5 MovieClips move down from _y:0 to _y:100 while fading from _alpha:0 to _alpha:100, and stagger the start times slightly by 0.2 seconds, you could do: TweenMax.allFromTo([mc1, mc2, mc3, mc4, mc5], 1, {_y:0, _alpha:0}, {_y:100, _alpha:100}, 0.2).
* @param onCompleteAll A function to call when all of the tweens have completed.
* @param onCompleteAllParams An Array of parameters to pass the onCompleteAll function when all the tweens have completed.
* @return Array of TweenMax instances
*/
public static function allFromTo(targets:Array, duration:Number, fromVars:Object, toVars:Object, stagger:Number, onCompleteAll:Function, onCompleteAllParams:Array, onCompleteAllScope:Object):Array {
toVars.startAt = fromVars;
if (fromVars.immediateRender) {
toVars.immediateRender = true;
}
return allTo(targets, duration, toVars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope);
}
/**
* Provides a simple way to call a function after a set amount of time (or frames). You can
* optionally pass any number of parameters to the function too. For example:
*
* TweenMax.delayedCall(1, myFunction, ["param1", 2]);
* function myFunction(param1:String, param2:Number):Void {
* trace("called myFunction and passed params: " + param1 + ", " + param2);
* }
*
* @param delay Delay in seconds (or frames if useFrames is true) before the function should be called
* @param onComplete Function to call
* @param onCompleteParams An Array of parameters to pass the function.
* @return TweenMax instance
*/
public static function delayedCall(delay:Number, onComplete:Function, onCompleteParams:Array, onCompleteScope:Object, useFrames:Boolean):TweenMax {
return new TweenMax(onComplete, 0, {delay:delay, onComplete:onComplete, onCompleteParams:onCompleteParams, onCompleteScope:onCompleteScope, immediateRender:false, useFrames:useFrames, overwrite:0});
}
/**
* Gets all the tweens of a particular object.
*
* @param target The target object whose tweens you want returned
* @return Array of tweens (could be TweenLite and/or TweenMax instances)
*/
public static function getTweensOf(target:Object):Array {
var a:Array = masterList[target].tweens;
var toReturn:Array = [];
if (a) {
var i:Number = a.length;
while (i--) {
if (!a[i].gc) {
toReturn[toReturn.length] = a[i];
}
}
}
return toReturn;
}
/**
* Determines whether or not a particular object is actively tweening. If a tween
* is paused or hasn't started yet, it doesn't count as active.
*
* @param target Target object whose tweens you're checking
* @return Boolean value indicating whether or not any active tweens were found
*/
public static function isTweening(target:Object):Boolean {
var a:Array = getTweensOf(target);
var i:Number = a.length;
var tween:TweenLite;
while (i--) {
tween = a[i];
if ((tween.active || (tween.cachedStartTime == tween.timeline.cachedTime && tween.timeline.active))) {
return true;
}
}
return false;
}
/**
* Returns all tweens that are in the masterList. Tweens are automatically removed from the
* masterList when they complete and are not attached to a timeline that has
* autoRemoveChildren set to true.
*
* @return Array of TweenLite and/or TweenMax instances
*/
public static function getAllTweens():Array {
var ml:Object = masterList; //speeds things up slightly
var cnt:Number = 0;
var toReturn:Array = [], a:Array, i:Number;
for (var p:String in ml) {
a = ml[p].tweens;
i = a.length;
while (i--) {
if (!a[i].gc) {
toReturn[cnt++] = a[i];
}
}
}
return toReturn;
}
/**
* @private
* Kills all tweens and/or delayedCalls/callbacks, optionally forcing them to completion first.
*
* @param complete Determines whether or not the tweens/delayedCalls/callbacks should be forced to completion before being killed.
* @param tweens If true, all TweenLite/TweenMax instances will be killed
* @param delayedCalls If true, all delayedCalls will be killed. TimelineMax callbacks are treated the same as delayedCalls.
*/
public static function killAll(complete:Boolean, tweens:Boolean, delayedCalls:Boolean):Void {
if (tweens == undefined) {
tweens = true;
}
if (delayedCalls == undefined) {
delayedCalls = true;
}
var a:Array = getAllTweens();
var isDC:Boolean; //is delayedCall
var i:Number = a.length;
while (i--) {
isDC = (a[i].target == a[i].vars.onComplete);
if (isDC == delayedCalls || isDC != tweens) {
if (complete == true) {
a[i].complete(false, false);
} else {
a[i].setEnabled(false, false);
}
}
}
}
/**
* Kills all tweens of the children of a particular MovieClip, optionally forcing them to completion first.
*
* @param parent The MovieClip whose children should no longer be affected by any tweens.
* @param complete Determines whether or not the tweens and/or delayedCalls should be forced to completion before being killed.
*/
public static function killChildTweensOf(parent:MovieClip, complete:Boolean):Void {
var a:Array = getAllTweens();
var curTarget:Object, curParent:MovieClip;
var i:Number = a.length;
while (i--) {
curTarget = a[i].target;
if (curTarget instanceof MovieClip) {
curParent = curTarget._parent;
while (curParent) {
if (curParent == parent) {
if (complete == true) {
a[i].complete(false, false);
} else {
a[i].setEnabled(false, false);
}
}
curParent = curParent._parent;
}
}
}
}
/**
* Pauses all TweenMax tweens and/or delayedCalls/callbacks.
*
* @param tweens If true, all TweenMax instances should be paused.
* @param delayedCalls If true, all delayedCalls will be paused. TimelineMax callbacks are treated the same as delayedCalls.
*/
public static function pauseAll(tweens:Boolean, delayedCalls:Boolean):Void {
changePause(true, tweens, delayedCalls);
}
/**
* Resumes all paused TweenMax tweens and/or delayedCalls/callbacks.
*
* @param tweens If true, all tweens will be resumed.
* @param delayedCalls If true, all delayedCalls will be resumed. TimelineMax callbacks are treated the same as delayedCalls.
*/
public static function resumeAll(tweens:Boolean, delayedCalls:Boolean):Void {
changePause(false, tweens, delayedCalls);
}
/**
* @private
* Changes the paused state of all TweenMax tweens and/or delayedCalls
*
* @param pause Desired paused state
* @param tweens If true, all TweenMax instances should be affected.
* @param delayedCalls If true, all delayedCalls will be affected.
*/
private static function changePause(pause:Boolean, tweens:Boolean, delayedCalls:Boolean):Void {
if (tweens == undefined) {
tweens = true;
}
if (delayedCalls == undefined) {
delayedCalls = true;
}
var a:Array = getAllTweens();
var isDC:Boolean; //is delayedCall
var i:Number = a.length;
while (i--) {
isDC = Boolean(a[i].target == a[i].vars.onComplete);
if (isDC == delayedCalls || isDC != tweens) {
a[i].paused = pause;
}
}
}
//---- GETTERS / SETTERS ----------------------------------------------------------------------------------------------------------
/**
* Value between 0 and 1 indicating the progress of the tween according to its duration
* where 0 is at the beginning, 0.5 is halfway finished, and 1 is finished. totalProgress,
* by contrast, describes the overall progress according to the tween's totalDuration
* which includes repeats and repeatDelays (if there are any). For example, if a TweenMax instance
* is set to repeat once, at the end of the first cycle totalProgress would only be 0.5
* whereas progress would be 1. If you tracked both properties over the course of the
* tween, you'd see progress go from 0 to 1 twice (once for each cycle) in the same
* time it takes the totalProgress 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 {
if (_cyclesComplete == 0) {
setTotalTime(this.duration * n, false);
} else {
setTotalTime(this.duration * n + (_cyclesComplete * this.cachedDuration), false);
}
}
/**
* Value between 0 and 1 indicating the progress of the tween according to its totalDuration
* where 0 is at the beginning, 0.5 is halfway finished, and 1 is finished. progress,
* by contrast, describes the progress according to the tween's duration which does not
* include repeats and repeatDelays. For example, if a TweenMax instance is set to repeat
* once, at the end of the first cycle totalProgress would only be 0.5
* whereas progress would be 1. If you tracked both properties over the course of the
* tween, you'd see progress go from 0 to 1 twice (once for each cycle) in the same
* time it takes the totalProgress property to go from 0 to 1 once.
**/
public function get totalProgress():Number {
return this.cachedTotalTime / this.totalDuration;
}
public function set totalProgress(n:Number):Void {
setTotalTime(this.totalDuration * n, false);
}
/** @inheritDoc **/
public function get currentTime():Number {
return this.cachedTime;
}
public function set currentTime(n:Number):Void {
if (_cyclesComplete == 0) {
//no change needed
} else if (this.yoyo && (_cyclesComplete % 2 == 1)) {
n = (this.duration - n) + (_cyclesComplete * (this.cachedDuration + _repeatDelay));
} else {
n += (_cyclesComplete * (this.duration + _repeatDelay));
}
setTotalTime(n, false);
}
/**
* Duration of the tween in seconds (or frames for frames-based timelines) including any repeats
* or repeatDelays. "duration", by contrast, does NOT include repeats and repeatDelays.
**/
public function get totalDuration():Number {
if (this.cacheIsDirty) {
//instead of Infinity, we use 999999999999 so that we can accommodate reverses
this.cachedTotalDuration = (_repeat == -1) ? 999999999999 : this.cachedDuration * (_repeat + 1) + (_repeatDelay * _repeat);
this.cacheIsDirty = false;
}
return this.cachedTotalDuration;
}
public function set totalDuration(n:Number):Void {
if (_repeat == -1) {
return;
}
this.duration = (n - (_repeat * _repeatDelay)) / (_repeat + 1);
}
/** 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);
}
/** Number of times that the tween should repeat; -1 repeats indefinitely. **/
public function get repeat():Number {
return _repeat;
}
public function set repeat(n:Number):Void {
_repeat = n;
setDirtyCache(true);
}
/** Amount of time in seconds (or frames for frames-based tweens) between repeats **/
public function get repeatDelay():Number {
return _repeatDelay;
}
public function set repeatDelay(n:Number):Void {
_repeatDelay = n;
setDirtyCache(true);
}
/** Multiplier describing the speed of the root timelines where 1 is normal speed, 0.5 is half-speed, 2 is double speed, etc. **/
public static function get globalTimeScale():Number {
return (TweenLite.rootTimeline == undefined) ? 1 : TweenLite.rootTimeline.cachedTimeScale;
}
public static function set globalTimeScale(n:Number):Void {
if (n == 0) { //can't allow zero because it'll throw the math off
n = 0.0001;
}
if (TweenLite.rootTimeline == undefined) {
TweenLite.to({}, 0, {}); //forces initialization in case globalTimeScale is set before any tweens are created.
}
var tl:SimpleTimeline = TweenLite.rootTimeline;
var curTime:Number = (getTimer() * 0.001)
tl.cachedStartTime = curTime - ((curTime - tl.cachedStartTime) * tl.cachedTimeScale / n);
tl = TweenLite.rootFramesTimeline;
curTime = TweenLite.rootFrame;
tl.cachedStartTime = curTime - ((curTime - tl.cachedStartTime) * tl.cachedTimeScale / n);
TweenLite.rootFramesTimeline.cachedTimeScale = TweenLite.rootTimeline.cachedTimeScale = n;
}
}