/** @language english
* <p>LTweenLite is an extremely fast, lightweight, and flexible animation tool that serves as the foundation Animation Platform.</p>
* @class LTweenLite
* @constructor
* @since 1.4.0
* @public
*/
var LTweenLiteTimeline;
var LTweenLite = (function () {
function LTweenLiteChild ($target, $duration, $vars) {
var s = this;
LExtends (s, LObject, []);
s.type = "LTweenLiteChild";
s.toNew = [];
s.init($target, $duration, $vars);
}
var p = {
init : function($target, $duration, $vars) {
var s = this, k = null;
if (typeof $vars["tweenTimeline"] == UNDEFINED) {
$vars["tweenTimeline"] = LTweenLite.TYPE_FRAME;
}
s.target = $target;
s.duration = $duration || 0.001;
s.vars = $vars;
s.delay = s.vars.delay || 0;
if(s.vars["tweenTimeline"] == LTweenLite.TYPE_TIMER){
s.currentTime = (new Date()).getTime() / 1000;
s.initTime = s.currentTime;
s.startTime = s.initTime + s.delay;
}else{
s.currentTime = 0;
s.duration *= 1000;
s.currentTime -= s.delay * 1000;
}
s.combinedTimeScale = s.vars.timeScale || 1;
s.active = s.duration == 0 && s.delay == 0;
s.varsto = {};
s.varsfrom = {};
s.stop = false;
if (typeof(s.vars.ease) != "function") {
s.vars.ease = LEasing.None.easeIn;
}
s.ease = s.vars.ease;
delete s.vars.ease;
if (s.vars.onComplete) {
s.onComplete = s.vars.onComplete;
delete s.vars.onComplete;
}
if (s.vars.onUpdate) {
s.onUpdate = s.vars.onUpdate;
delete s.vars.onUpdate;
}
if (s.vars.onStart) {
s.onStart = s.vars.onStart;
delete s.vars.onStart;
}
for (k in s.vars) {
s.varsto[k] = s.vars[k];
s.varsfrom[k] = s.target[k];
}
},
pause : function () {
this.stop = true;
},
resume : function () {
this.stop = false;
},
tween : function () {
var s = this, tweentype;
var type_timer = (s.vars["tweenTimeline"] == LTweenLite.TYPE_TIMER);
if (type_timer) {
var time = (new Date()).getTime() / 1000, etime = time - s.startTime;
if (etime < 0) {
return;
}
} else {
if (s.stop) {
return;
}
s.currentTime += LGlobal.speed;
if (s.currentTime < 0) {
return;
}
}
for (tweentype in s.varsto) {
if (tweentype == "tweenTimeline") {
continue;
}
if (type_timer) {
s.target[tweentype] = s.ease(etime, s.varsfrom[tweentype], s.varsto[tweentype] - s.varsfrom[tweentype], s.duration);
} else {
s.target[tweentype] = s.ease(s.currentTime, s.varsfrom[tweentype], s.varsto[tweentype] - s.varsfrom[tweentype], s.duration);
}
}
if (s.onStart) {
s.onStart(s.target);
delete s.onStart;
}
var e;
if (type_timer) {
e = (etime >= s.duration);
} else {
e = (s.currentTime >= s.duration);
}
if (e) {
for (tweentype in s.varsto) {
s.target[tweentype] = s.varsto[tweentype];
}
if (s.onComplete) {
s.target.target = s.target;
s.target.currentTarget = s;
s.onComplete(s.target);
delete s.target.currentTarget;
delete s.target.target;
}
return true;
} else if (s.onUpdate) {
s.onUpdate(s.target);
}
return false;
},
to : function ($target, $duration, $vars) {
var s = this;
s.toNew.push({target : $target, duration : $duration, vars : $vars});
return s;
},
keep : function () {
var s = this, t, vs, k;
if (s.toNew.length > 0) {
t = s.toNew.shift();
if (t.vars.loop) {
s.loop = true;
}
if (s.loop) {
vs = {};
for (k in t.vars) {
vs[k] = t.vars[k];
}
s.to(t.target, t.duration, vs);
}
s.init(t.target, t.duration, t.vars);
return true;
}
return false;
}
};
for (var k in p) {
LTweenLiteChild.prototype[k] = p[k];
}
function LTweenLite () {
LExtends (this, LObject, []);
this.type = "LTweenLite";
}
LTweenLite.TYPE_FRAME = "type_frame";
LTweenLite.TYPE_TIMER = "type_timer";
p = {
tweens : [],
ll_show : null,
frame : function(){
var s = this;
var i, length = s.tweens.length, t;
for (i = 0; i < length; i++) {
t = s.tweens[i];
if (t && t.tween && t.tween()) {
s.tweens.splice(i, 1);
i--;
length = s.tweens.length;
if (t.keep()) {
s.add(t);
}
}
}
if (s.tweens.length == 0) {
s.ll_show = null;
}
},
/** @language english
* Static method for creating a LTweenLiteChild instance that animates to the specified destination values (from the current values).
* @method LTweenLite.to
* @static
* @param {Object} target Target object (or array of objects) whose properties this tween affects.
* @param {float} duration Duration in seconds (or frames if useFrames:true is set in the vars parameter).
* @param {Object} vars <p>An object defining the end value for each property that should be tweened as well as any special properties like onComplete, ease, etc. For example, to tween mc.x to 100 and mc.y to 200 and then call myFunction, do this: TweenLite.to(mc, 1, {x:100, y:200, onComplete:myFunction});</p>
* <p>Typically the vars parameter is used to define ending values for tweening properties of the target like {x:100, y:200, alpha:0}, but the following optional special properties serve other purposes:</p>
* <table>
* <tr><th>Property</th><th>Type</th><th>Explanation</th></tr>
* <tr><td>delay</td><td>float</td><td>Amount of delay in seconds (or frames for frames-based tweens) before the tween should begin.</td></tr>
* <tr><td>ease</td><td>LEasing</td><td>LEasing (or Function) - You can choose from various eases to control the rate of change during the animation, giving it a specific "feel". For example, LEasing.Quad.easeIn or LEasing.Cubic.easeOut. For best performance, use one of the eases. The default is LEasing.None.easeIn.</td></tr>
* <tr><td>onComplete</td><td>Function</td><td>A function that should be called when the tween has completed</td></tr>
* <tr><td>onStart</td><td>Function</td><td>A function that should be called when the tween begins (when its time changes from 0 to some other value which can happen more than once if the tween is restarted multiple times).</td></tr>
* <tr><td>onUpdate</td><td>Function</td><td>A function that should be called every time the tween updates (on every frame while the tween is active)</td></tr>
* <tr><td>loop</td><td>Boolean</td><td>If true, the tween will loop when it reaches the end. Can be set via the props param.</td></tr>
* </table>
* @return {LTweenLiteChild} LTweenLiteChild instance
* @example
* LInit(1000/50,"legend",800,450,main);
* function main(){
* LGlobal.setDebug(true);
* var circle = new LSprite();
* circle.x = 50;
* circle.y = 50;
* circle.graphics.drawArc("#FF0000",1,[0,0,20,0,Math.PI*2],true,"#FF0000");
* addChild(circle);
* var rect = new LSprite();
* rect.x = 50;
* rect.y = 100;
* rect.graphics.drawRect("#FF00FF",1,[0,0,20,20],true,"#FF00FF");
* addChild(rect);
* LTweenLite.to(circle,2,{x:500,y:400,scaleX:3,scaleY:3,ease:LEasing.Strong.easeInOut})
* .to(circle,2,{x:700,y:50,scaleX:1,scaleY:1,ease:LEasing.Quint.easeIn,onComplete:function(e){
* trace(e.currentTarget);
* trace(e.target);
* }});
* LTweenLite.to(rect,1,{x:500,loop:true,ease:LEasing.Sine.easeInOut})
* .to(rect,1,{x:50,ease:LEasing.Quad.easeInOut});
* }
* @examplelink <p><a href="../../../api/LTweenLite/to.html" target="_blank">Try it »</a></p>
* @public
* @since 1.4.0
*/
to : function ($target, $duration, $vars) {
if (!$target) {
return;
}
var s = this;
var tween = new LTweenLiteChild({}, 0, {});
s.tweens.push(tween);
s.ll_show = s.frame;
tween.to($target, $duration, $vars);
return tween;
},
add : function (tween) {
this.tweens.push(tween);
},
/** @language english
* Static method to stop a tween affect.
* @method LTweenLite.remove
* @static
* @param {LTweenLiteChild} tween a tween affect.
* @example
* LInit(1000/50,"legend",800,450,main);
* var tween;
* function main(){
* LGlobal.setDebug(true);
* var rect = new LSprite();
* rect.x = 50;
* rect.y = 50;
* rect.graphics.drawRect("#FF00FF",1,[0,0,20,20],true,"#FF00FF");
* addChild(rect);
* tween = LTweenLite.to(rect,1,{x:500,loop:true,ease:LEasing.Sine.easeInOut})
* .to(rect,1,{x:50,ease:LEasing.Quad.easeInOut});
* var stopButton = new LButtonSample1("stop");
* stopButton.x = 50;
* circle.y = 50;
* stopButton.y = 100;
* addChild(stopButton);
* stopButton.addEventListener(LMouseEvent.MOUSE_UP,stopTween);
* }
* function stopTween(e){
* LTweenLite.remove(tween);
* }
* @examplelink <p><a href="../../../api/LTweenLite/remove.html" target="_blank">Try it »</a></p>
* @public
* @since 1.8.0
*/
remove : function (tween) {
var s = this;
if (typeof tween == UNDEFINED) {
return;
}
for (i = 0, l = s.tweens.length; i < l; i++) {
if (tween.objectIndex == s.tweens[i].objectIndex) {
s.tweens.splice(i, 1);
break;
}
}
},
/** @language english
* Static method to stop all the tween affects.
* @method LTweenLite.removeAll
* @static
* @example
* LInit(1000/50,"legend",800,450,main);
* var tween;
* function main(){
* LGlobal.setDebug(true);
* var rect = new LSprite();
* rect.x = 50;
* rect.y = 50;
* rect.graphics.drawRect("#FF00FF",1,[0,0,20,20],true,"#FF00FF");
* addChild(rect);
* tween = LTweenLite.to(rect,1,{x:500,loop:true,ease:LEasing.Sine.easeInOut})
* .to(rect,1,{x:50,ease:LEasing.Quad.easeInOut});
* var stopButton = new LButtonSample1("stop");
* stopButton.x = 50;
* circle.y = 50;
* stopButton.y = 100;
* addChild(stopButton);
* stopButton.addEventListener(LMouseEvent.MOUSE_UP,stopTween);
* }
* function stopTween(e){
* LTweenLite.remove(tween);
* }
* @examplelink <p><a href="../../../api/LTweenLite/remove.html" target="_blank">Try it »</a></p>
* @public
* @since 1.8.0
*/
removeAll : function () {
this.tweens.splice(0, this.tweens.length);
}
};
for (var k in p) {
LTweenLite.prototype[k] = p[k];
}
LTweenLiteTimeline = new LTweenLite();
LGlobal.childList.push(LTweenLiteTimeline);
var tween = new LTweenLite();
tween.TYPE_FRAME = LTweenLite.TYPE_FRAME;
tween.TYPE_TIMER = LTweenLite.TYPE_TIMER;
LGlobal.childList.push(tween);
return tween;
})();