📄 tweenlite.as
字号:
6.1:
- Ensured that even thousands of tweens are synced (uses an internally-controlled timer)
- Removed support for mcColor (in favor of "tint")
6.04:
- Fixed bug that caused calls to complete() to not render if the tween hadn't ever started (like if there was a delay that hadn't expired yet)
6.03:
- Added the "renderOnStart" property that can force TweenLite.from() to render only when the tween actually starts (by default, it renders immediately even if the tween has a delay.)
6.02:
- Fixed bug that could cause TweenLite.delayedCall() to generate a 1010 error.
6.01:
- Fixed bug that could cause TweenLite.from() to not render the values immediately.
- Fixed bug that could prevent tweens with a duration of zero from rendering properly.
6.0:
- Added ability to tween a MovieClip's frame
- Added onCompleteScope, onStartScope, and onUpdateScope
- Reworked internal class routines for handling SubTweens
CODED BY: Jack Doyle, jack@greensock.com
Copyright 2008, GreenSock (This work is subject to the terms in http://www.greensock.com/terms_of_use.html.)
*/
package gs {
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.geom.ColorTransform;
import flash.utils.*;
public class TweenLite {
public static var version:Number = 9.29;
public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
public static var defaultEase:Function = TweenLite.easeOut;
public static var overwriteManager:Object; //makes it possible to integrate the gs.utils.tween.OverwriteManager for adding autoOverwrite capabilities
public static var currentTime:uint;
public static var masterList:Dictionary = new Dictionary(false); //Holds references to all our instances.
public static var timingSprite:Sprite = new Sprite(); //A reference to the sprite that we use to drive all our ENTER_FRAME events.
private static var _classInitted:Boolean;
private static var _timer:Timer = new Timer(2000);
public var duration:Number; //Duration (in seconds)
public var vars:Object; //Variables (holds things like alpha or y or whatever we're tweening)
public var delay:Number; //Delay (in seconds)
public var startTime:Number; //Start time
public var initTime:Number; //Time of initialization. Remember, we can build in delays so this property tells us when the frame action was born, not when it actually started doing anything.
public var tweens:Array; //Contains parsed data for each property that's being tweened (target, property, start, change, and name).
public var target:Object; //Target object
public var active:Boolean;
public var ease:Function;
public var initted:Boolean;
public var combinedTimeScale:Number; //even though TweenLite doesn't use this variable, TweenFilterLite and TweenMax do and it optimized things to store it here, particularly for TweenGroup
public var gc:Boolean; //flagged for garbage collection
public var started:Boolean;
protected var _subTweens:Array; //Only used for associated sub-tweens like tint and volume
protected var _hst:Boolean; //Has sub-tweens. Tracking this as a Boolean value is faster than checking _subTweens.length
protected var _hasUpdate:Boolean; //has onUpdate. Tracking this as a Boolean value is faster than checking this.vars.onUpdate == null.
protected var _isDisplayObject:Boolean; //We need to know if the target is a DisplayObject so that we can apply visibility changes, do tint and Sound tweens, etc
protected var _specialVars:Object; //Helps when using TweenLiteVars, TweenFilterLiteVars, or TweenMaxVars as the this.vars object because certain properties are only exposed via vars.exposedProps (for example, the "visible" property is Boolean, so we cannot normally check to see if it's undefined)
public function TweenLite($target:Object, $duration:Number, $vars:Object) {
if ($target == null) {return};
if (!_classInitted) {
currentTime = getTimer();
timingSprite.addEventListener(Event.ENTER_FRAME, updateAll, false, 0, true);
if (overwriteManager == null) {
overwriteManager = {mode:1, enabled:false};
}
_timer.addEventListener("timer", killGarbage, false, 0, true);
_timer.start();
_classInitted = true;
}
this.vars = $vars;
this.duration = $duration || 0.001; //Easing equations don't work when the duration is zero.
this.delay = $vars.delay || 0;
this.combinedTimeScale = $vars.timeScale || 1;
this.active = Boolean($duration == 0 && this.delay == 0);
this.target = $target;
_isDisplayObject = Boolean($target is DisplayObject);
if (!(this.vars.ease is Function)) {
this.vars.ease = defaultEase;
}
if (this.vars.easeParams != null) {
this.vars.proxiedEase = this.vars.ease;
this.vars.ease = easeProxy;
}
this.ease = this.vars.ease;
if (!isNaN(Number(this.vars.autoAlpha))) {
this.vars.alpha = Number(this.vars.autoAlpha);
this.vars.visible = Boolean(this.vars.alpha > 0);
}
_specialVars = (this.vars.isTV == true) ? this.vars.exposedProps : this.vars; //for TweenLiteVars, TweenFilterLiteVars, and TweenMaxVars
this.tweens = [];
_subTweens = [];
_hst = this.initted = false;
this.initTime = currentTime;
this.startTime = this.initTime + (this.delay * 1000);
var mode:int = ($vars.overwrite == undefined || (!overwriteManager.enabled && $vars.overwrite > 1)) ? overwriteManager.mode : int($vars.overwrite);
if (masterList[$target] == undefined || ($target != null && mode == 1)) {
masterList[$target] = [];
}
masterList[$target].push(this);
if ((this.vars.runBackwards == true && this.vars.renderOnStart != true) || this.active) {
initTweenVals();
if (this.active) { //Means duration is zero and delay is zero, so render it now, but add one to the startTime because this.duration is always forced to be at least 0.001 since easing equations can't handle zero.
render(this.startTime + 1);
} else {
render(this.startTime);
}
if (_specialVars.visible != null && this.vars.runBackwards == true && _isDisplayObject) {
this.target.visible = _specialVars.visible;
}
}
}
public function initTweenVals($hrp:Boolean = false, $reservedProps:String = ""):void {
var p:String, i:int;
if (!$hrp && overwriteManager.enabled) {
overwriteManager.manageOverwrites(this, masterList[this.target]);
}
if (this.target is Array) {
var endArray:Array = this.vars.endArray || [];
for (i = 0; i < endArray.length; i++) {
if (this.target[i] != endArray[i] && this.target[i] != undefined) {
this.tweens[this.tweens.length] = [this.target, i.toString(), this.target[i], endArray[i] - this.target[i], i.toString()]; //[object, property, start, change, name]
}
}
} else {
if ((typeof(_specialVars.tint) != "undefined" || this.vars.removeTint == true) && _isDisplayObject) { //If we're trying to change the color of a DisplayObject, then set up a quasai proxy using an instance of a TweenLite to control the color.
var clr:ColorTransform = this.target.transform.colorTransform;
var endClr:ColorTransform = new ColorTransform();
if (_specialVars.alpha != undefined) {
endClr.alphaMultiplier = _specialVars.alpha;
delete _specialVars.alpha;
} else {
endClr.alphaMultiplier = this.target.alpha;
}
if (this.vars.removeTint != true && ((_specialVars.tint != null && _specialVars.tint != "") || _specialVars.tint == 0)) { //In case they're actually trying to remove the colorization, they should pass in null or "" for the tint
endClr.color = _specialVars.tint;
}
addSubTween("tint", tintProxy, {progress:0}, {progress:1}, {target:this.target, color:clr, endColor:endClr});
}
if (_specialVars.frame != null && _isDisplayObject) {
addSubTween("frame", frameProxy, {frame:this.target.currentFrame}, {frame:_specialVars.frame}, {target:this.target});
}
if (!isNaN(this.vars.volume) && this.target.hasOwnProperty("soundTransform")) { //If we're trying to change the volume of an object with a soundTransform property, then set up a quasai proxy using an instance of a TweenLite to control the volume.
addSubTween("volume", volumeProxy, this.target.soundTransform, {volume:this.vars.volume}, {target:this.target});
}
if (_specialVars.visible != null && _isDisplayObject) {
addSubTween("visible", visibleProxy, {}, {}, {tween:this});
}
for (p in _specialVars) {
if (p == "ease" || p == "delay" || p == "overwrite" || p == "onComplete" || p == "onCompleteParams" || p == "runBackwards" || p == "visible" || p == "autoOverwrite" || p == "persist" || p == "onUpdate" || p == "onUpdateParams" || p == "autoAlpha" || (p == "timeScale" && !(this.target is TweenLite)) || p == "onStart" || p == "onStartParams" ||p == "renderOnStart" || p == "proxiedEase" || p == "easeParams" || ($hrp && $reservedProps.indexOf(" " + p + " ") != -1)) {
} else if (!(_isDisplayObject && (p == "tint" || p == "removeTint" || p == "frame")) && !(p == "volume" && this.target.hasOwnProperty("soundTransform"))) {
//if (this.target.hasOwnProperty(p)) { //REMOVED because there's a bug in Flash Player 10 (Beta) that incorrectly reports that DisplayObjects don't have a "z" property. This check wasn't entirely necessary anyway - it just prevented runtime errors if/when developers tried tweening properties that didn't exist.
if (typeof(_specialVars[p]) == "number") {
this.tweens[this.tweens.length] = [this.target, p, this.target[p], _specialVars[p] - this.target[p], p]; //[object, property, start, change, name]
} else {
this.tweens[this.tweens.length] = [this.target, p, this.target[p], Number(_specialVars[p]), p]; //[object, property, start, change, name]
}
//}
}
}
}
if (this.vars.runBackwards == true) {
var tp:Object;
for (i = this.tweens.length - 1; i > -1; i--) {
tp = this.tweens[i];
tp[2] += tp[3];
tp[3] *= -1;
}
}
if (this.vars.onUpdate != null) {
_hasUpdate = true;
}
this.initted = true;
}
protected function addSubTween($name:String, $proxy:Function, $target:Object, $props:Object, $info:Object = null):void {
_subTweens[_subTweens.length] = {name:$name, proxy:$proxy, target:$target, info:$info};
for (var p:String in $props) {
if (typeof($props[p]) == "number") {
this.tweens[this.tweens.length] = [$target, p, $target[p], $props[p] - $target[p], $name]; //[object, property, start, change, name]
} else {
this.tweens[this.tweens.length] = [$target, p, $target[p], Number($props[p]), $name]; //[object, property, start, change, name]
}
}
_hst = true; //has sub tweens. We track this with a boolean value as opposed to checking _subTweens.length for speed purposes
}
public static function to($target:Object, $duration:Number, $vars:Object):TweenLite {
return new TweenLite($target, $duration, $vars);
}
public static function from($target:Object, $duration:Number, $vars:Object):TweenLite {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -