August 4
Dynamic Tween using Standard AS 2.0 Tween Class
I haven’t been working with the Tween class, and thought I would revisit it and add a looping function to pre-populate an unlimited number of tweens using one tween function. Code is below and you can download the source code here.
import mx.transitions.Tween;
import mx.transitions.easing.*;
// Constants
_global.xPos = 20;
_global.tweenNum = 1;
_global.timeVar = 1;
_global.timeReduction = .15;
function tweenBall():Void {
var nextDepth:Number = this.getNextHighestDepth();
_root.attachMovie(“ballClip”,”ballClip”+tweenNum,nextDepth,{_x:Stage.width, _y:200});
_global.xSpacing = _root["ballClip"+tweenNum]._width+20;
// Set tweens for different properties of object animated
var tweenXpos:Object = new Tween(_root["ballClip"+tweenNum], “_x”, Regular.easeOut, Stage.width, xPos, timeVar, true);
var tweenAlpha:Object = new Tween(_root["ballClip"+tweenNum], “_alpha”, Regular.easeOut, 0, 100, timeVar, true);
tweenXpos.onMotionFinished = function() {
if (tweenNum<5) {
// set new variables for next tween
_global.tweenNum++;
_global.xPos = xPos+xSpacing;
_global.timeVar = timeVar-timeReduction;
if (timeVar<=0) {
_global.timeVar = .1;
}
tweenBall();
}
};
}
tweenBall();