📄 tweenlitevars.as
字号:
/*
VERSION: 2.03
DATE: 1/30/2009
ACTIONSCRIPT VERSION: 3.0
DESCRIPTION:
There are 2 primary benefits of using this utility to define your TweenLite variables:
1) In most code editors, code hinting will be activated which helps remind you which special properties are available in TweenLite
2) It allows you to code using strict datatyping (although it doesn't force you to).
USAGE:
Instead of TweenLite.to(my_mc, 1, {x:300, tint:0xFF0000, onComplete:myFunction}), you could use this utility like:
var myVars:TweenLiteVars = new TweenLiteVars();
myVars.addProp("x", 300); // use addProp() to add any property that doesn't already exist in the TweenLiteVars instance.
myVars.tint = 0xFF0000;
myVars.onComplete = myFunction;
TweenLite.to(my_mc, 1, myVars);
Or if you just want to add multiple properties with one function, you can add up to 15 with the addProps() function, like:
var myVars:TweenLiteVars = new TweenLiteVars();
myVars.addProps("x", 300, false, "y", 100, false, "scaleX", 1.5, false, "scaleY", 1.5, false);
myVars.onComplete = myFunction;
TweenLite.to(my_mc, 1, myVars);
NOTES:
- This class adds about 13 Kb to your published SWF (including all dependencies).
- This utility is completely optional. If you prefer the shorter synatax in the regular TweenLite class, feel
free to use it. The purpose of this utility is simply to enable code hinting and to allow for strict datatyping.
- You may add custom properties to this class if you want, but in order to expose them to TweenLite, make sure
you also add a getter and a setter that adds the property to the _exposedVars Object.
- You can reuse a single TweenLiteVars Object for multiple tweens if you want, but be aware that there are a few
properties that must be handled in a special way, and once you set them, you cannot remove them. Those properties
are: frame, visible, tint, and volume. If you are altering these values, it might be better to avoid reusing a TweenLiteVars
Object.
AUTHOR: Jack Doyle, jack@greensock.com
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.
*/
package gs.utils.tween {
import gs.TweenLite;
dynamic public class TweenLiteVars {
public static const version:Number = 2.03;
public const isTV:Boolean = true; // (stands for "isTweenVars") - Just gives us a way to check inside TweenLite to see if the Object is a TweenLiteVars without having to embed the class. This is helpful when handling tint, visible, and other properties that the user didn't necessarily define, but this utility class forces to be present.
/**
* The number of seconds to delay before the tween begins.
*/
public var delay:Number = 0;
/**
* An easing function (i.e. fl.motion.easing.Elastic.easeOut) The default is Regular.easeOut.
*/
public var ease:Function;
/**
* An Array of extra parameter values to feed the easing equation (beyond the standard 4). This can be useful with easing equations like Elastic that accept 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.
*/
public var easeParams:Array;
/**
* A function to call when the tween begins. This can be useful when there's a delay and you want something to happen just as the tween begins.
*/
public var onStart:Function;
/**
* An Array of parameters to pass the onStart function.
*/
public var onStartParams:Array;
/**
* A function to call whenever the tweening values are updated (on every frame during the time the tween is active).
*/
public var onUpdate:Function;
/**
* An Array of parameters to pass the onUpdate function
*/
public var onUpdateParams:Array;
/**
* A function to call when the tween has completed.
*/
public var onComplete:Function;
/**
* An Array of parameters to pass the onComplete function
*/
public var onCompleteParams:Array;
/**
* NONE = 0, ALL = 1, AUTO* = 2, CONCURRENT* = 3 *Only available with the optional OverwriteManager add-on class which must be initted once for TweenLite or TweenFilterLite, like OverwriteManager.init(). TweenMax automatically inits OverwriteManager.
*/
public var overwrite:int = 2;
/**
* To prevent a tween from getting garbage collected after it completes, set persist to true. This does NOT, however, prevent teh tween from getting overwritten by other tweens of the same target.
*/
public var persist:Boolean = false;
/**
* If you're using TweenLite.from() with a delay and you want to prevent the tween from rendering until it actually begins, set this special property to true. By default, it's false which causes TweenLite.from() to render its values immediately, even before the delay has expired.
*/
public var renderOnStart:Boolean = false;
/**
* Primarily used in from() calls - forces the values to get flipped.
*/
public var runBackwards:Boolean = false;
/**
* Defines starting values for the tween (by default, the target's current values at the time the tween begins are used)
*/
public var startAt:TweenLiteVars;
protected var _exposedVars:Object; // Gives us a way to make certain non-dynamic properties enumerable.
protected var _autoAlpha:Number;
protected var _endArray:Array;
protected var _frame:int;
protected var _frameLabel:String;
protected var _removeTint:Boolean;
protected var _tint:uint;
protected var _visible:Boolean = true;
protected var _volume:Number;
protected var _bevelFilter:BevelFilterVars;
protected var _bezier:Array;
protected var _bezierThrough:Array;
protected var _blurFilter:BlurFilterVars;
protected var _colorMatrixFilter:ColorMatrixFilterVars;
protected var _dropShadowFilter:DropShadowFilterVars;
protected var _glowFilter:GlowFilterVars;
protected var _hexColors:Object;
protected var _orientToBezier:Array;
protected var _quaternions:Object;
protected var _setSize:Object;
protected var _shortRotation:Object;
protected var _transformAroundPoint:TransformAroundPointVars;
protected var _transformAroundCenter:TransformAroundCenterVars;
protected var _colorTransform:ColorTransformVars;
/**
* @param $vars An Object containing properties that correspond to the properties you'd like to add to this TweenLiteVars Object. For example, TweenLiteVars({x:300, onComplete:myFunction})
*/
public function TweenLiteVars($vars:Object = null) {
_exposedVars = {};
if ($vars != null) {
for (var p:String in $vars) {
if (p == "blurFilter" || p == "glowFilter" || p == "colorMatrixFilter" || p == "bevelFilter" || p == "dropShadowFilter" || p == "transformAroundPoint" || p == "transformAroundCenter" || p == "colorTransform") {
//ignore SubVars - they must be handled differently later...
} else if (p != "protectedVars") {
this[p] = $vars[p];
}
}
if ($vars.blurFilter != null) {
this.blurFilter = BlurFilterVars.createFromGeneric($vars.blurFilter);
}
if ($vars.bevelFilter != null) {
this.bevelFilter = BevelFilterVars.createFromGeneric($vars.bevelFilter);
}
if ($vars.colorMatrixFilter != null) {
this.colorMatrixFilter = ColorMatrixFilterVars.createFromGeneric($vars.colorMatrixFilter);
}
if ($vars.dropShadowFilter != null) {
this.dropShadowFilter = DropShadowFilterVars.createFromGeneric($vars.dropShadowFilter);
}
if ($vars.glowFilter != null) {
this.glowFilter = GlowFilterVars.createFromGeneric($vars.glowFilter);
}
if ($vars.transformAroundPoint != null) {
this.transformAroundPoint = TransformAroundPointVars.createFromGeneric($vars.transformAroundPoint);
}
if ($vars.transformAroundCenter != null) {
this.transformAroundCenter = TransformAroundCenterVars.createFromGeneric($vars.transformAroundCenter);
}
if ($vars.colorTransform != null) {
this.colorTransform = ColorTransformVars.createFromGeneric($vars.colorTransform);
}
if ($vars.protectedVars != null) { //used for clone()-ing protected vars
var pv:Object = $vars.protectedVars;
for (p in pv) {
this[p] = pv[p];
}
}
}
if (TweenLite.version < 10.05) {
trace("TweenLiteVars error! Please update your TweenLite class or try deleting your ASO files. TweenLiteVars requires a more recent version. Download updates at http://www.TweenLite.com.");
}
}
/**
* Adds a dynamic property for tweening and allows you to set whether the end value is relative or not
*
* @param $name Property name
* @param $value Numeric end value (or beginning value for from() calls)
* @param $relative If true, the value will be relative to the target's current value. For example, if my_mc.x is currently 300 and you do addProp("x", 200, true), the end value will be 500.
*/
public function addProp($name:String, $value:Number, $relative:Boolean = false):void {
if ($relative) {
this[$name] = String($value);
} else {
this[$name] = $value;
}
}
/**
* Adds up to 15 dynamic properties at once (just like doing addProp() multiple times). Saves time and reduces code.
*/
public function addProps($name1:String, $value1:Number, $relative1:Boolean = false,
$name2:String = null, $value2:Number = 0, $relative2:Boolean = false,
$name3:String = null, $value3:Number = 0, $relative3:Boolean = false,
$name4:String = null, $value4:Number = 0, $relative4:Boolean = false,
$name5:String = null, $value5:Number = 0, $relative5:Boolean = false,
$name6:String = null, $value6:Number = 0, $relative6:Boolean = false,
$name7:String = null, $value7:Number = 0, $relative7:Boolean = false,
$name8:String = null, $value8:Number = 0, $relative8:Boolean = false,
$name9:String = null, $value9:Number = 0, $relative9:Boolean = false,
$name10:String = null, $value10:Number = 0, $relative10:Boolean = false,
$name11:String = null, $value11:Number = 0, $relative11:Boolean = false,
$name12:String = null, $value12:Number = 0, $relative12:Boolean = false,
$name13:String = null, $value13:Number = 0, $relative13:Boolean = false,
$name14:String = null, $value14:Number = 0, $relative14:Boolean = false,
$name15:String = null, $value15:Number = 0, $relative15:Boolean = false):void {
addProp($name1, $value1, $relative1);
if ($name2 != null) {
addProp($name2, $value2, $relative2);
}
if ($name3 != null) {
addProp($name3, $value3, $relative3);
}
if ($name4 != null) {
addProp($name4, $value4, $relative4);
}
if ($name5 != null) {
addProp($name5, $value5, $relative5);
}
if ($name6 != null) {
addProp($name6, $value6, $relative6);
}
if ($name7 != null) {
addProp($name7, $value7, $relative7);
}
if ($name8 != null) {
addProp($name8, $value8, $relative8);
}
if ($name9 != null) {
addProp($name9, $value9, $relative9);
}
if ($name10 != null) {
addProp($name10, $value10, $relative10);
}
if ($name11 != null) {
addProp($name11, $value11, $relative11);
}
if ($name12 != null) {
addProp($name12, $value12, $relative12);
}
if ($name13 != null) {
addProp($name13, $value13, $relative13);
}
if ($name14 != null) {
addProp($name14, $value14, $relative14);
}
if ($name15 != null) {
addProp($name15, $value15, $relative15);
}
}
/**
* Clones the TweenLiteVars object.
*/
public function clone():TweenLiteVars {
var vars:Object = {protectedVars:{}};
appendCloneVars(vars, vars.protectedVars);
return new TweenLiteVars(vars);
}
/**
* Works with clone() to copy all the necessary properties. Split apart from clone() to take advantage of inheritence for TweenMaxVars
*/
protected function appendCloneVars($vars:Object, $protectedVars:Object):void {
var props:Array, special:Array, i:int, p:String;
props = ["delay","ease","easeParams","onStart","onStartParams","onUpdate","onUpdateParams","onComplete","onCompleteParams","overwrite","persist","renderOnStart","runBackwards","startAt"];
for (i = props.length - 1; i > -1; i--) {
$vars[props[i]] = this[props[i]];
}
special = ["_autoAlpha",
"_bevelFilter",
"_bezier",
"_bezierThrough",
"_blurFilter",
"_colorMatrixFilter",
"_colorTransform",
"_dropShadowFilter",
"_endArray",
"_frame",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -