Tween Class

When it comes to tween classes you can use flash's default easing transitions, but sometimes they go a bit wonky although I cannot explain why. Using a well-documented tween class library like Tweener is thus quite useful at times. I began by using Tweener in AS2, which originally started as mctween so this just happens to be what I've always used. You may have looked at the code of other people's projects and seen either the caurina (tweener) or greensock (tweenlite/tweenmax) folders inside; its used in many flash things!

Tweener
// Download Tweener from: http://code.google.com/p/tweener/ // Read the Documentation: http://hosted.zeh.com.br/tweener/docs/en-us/

// to use Tweener you have to import it first import caurina.transitions.Tweener;

// EXAMPLE OF A REALLY LONG ONE with different features Tweener.addTween(myMovieClip, {x:100, y:100, alpha:0, time:1, delay:4, transition:"easeOutExpo", onStart:doSomething, onComplete:doSomethingAtTheEnd}); // this means that when the tween starts it will run the function "doSomething" // and on having completed it will run function "doSomethingAtTheEnd"

// delay - it starts after four seconds // time - it takes 1 second to animate the changes in alpha and x/y location // transition - many transitions to choose from. see http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html

// WITH base, using the original "base" object to create a fade out animation with a different time var myFade:Object = {alpha:0, time:1}; Tweener.addTween(myMovieClip, {base:myFade, time:2}); // note that inheritance is overwritten

// PAUSE EVERYTHING!!! // Pauses all tweenings taking place Tweener.pauseTweens;

// OOPS, LETS RESUME AGAIN!!! // Resumes all tweenings of a certain object Tweener.resumeTweens(myMC);

// Resume the _x, _y and _alpha tweening of a certain object Tweener.resumeTweens(myMC, "_x", "_y", "_alpha"); 




 * Tweener
 * Tweener - Documentation
 * Tweener - Transition Types

fl.transitions
The fl.transitions package contains classes that let you use ActionScript to create animation effects. You use the Tween and TransitionManager classes as the primary classes for customizing animation in ActionScript 3.0. For more info see: Adobe Flash fl.transitions.easing package This works quite fine but sometimes when there are many many many tweens then it has been known to go a bit weird.

Draw and tween it all in AS3

An example with flash's default transitions - a version created entirely in code! Including the drawing of the ball sprite.

http://dreamsyntax.org/patterns/swf/tweenclass_01.swf

import fl.transitions.*; import fl.transitions.easing.*;

// stage align must be added in order to use stageWidth accurately in AS3 stage.align = StageAlign.TOP_LEFT;

// creating a circle in AS3 and aligning it to stage size var circle_mc:Sprite = new Sprite; circle_mc.graphics.beginFill(Math.random * 0x00000); circle_mc.graphics.drawCircle(0,0,50); circle_mc.graphics.endFill; circle_mc.x = stage.stageWidth/2; circle_mc.y = 10; addChild(circle_mc);

// the start and finish value are calculated in terms of the circle's size and stage // in this case it will bounce directly on the edge of the stage! var startValue:Number = circle_mc.y; var finishValue:Number = stage.stageHeight-circle_mc.width/2; var duration:Number = 2;

// values for this tween have been defined in previous lines // although you could also just put it in directly! but this makes it easy to edit later! var myTween:Tween = new Tween(circle_mc, "y", Bounce.easeOut, startValue, finishValue, duration, true); myTween.looping = true; 

Shorter example

Here is another example with using an object on the stage called ball_mc, with everything written out inside the Tween.

import fl.transitions.*; import fl.transitions.easing.*; var ballTween:Tween = new Tween(ball_mc, "y", Bounce.easeOut, 0, 400, 1, true); ballTween.looping = true; 

Alternative Tween classes

 * TweenLite - "A Lightweight, FAST Tweening Engine" For AS2 and AS3. From their website: "TweenLite is an extremely fast, lightweight, and flexible tweening engine that serves as the foundation of the GreenSock Tweening Platform."


 * TweenMax – "TweenLite on Steroids" For AS2 and AS3. From their website: "TweenMax extends the extremely lightweight, fast TweenLite engine, adding many useful features like timeScale, AS3 event dispatching, updateTo, yoyo, repeat, repeatDelay, rounding, and more. It also activates many extra plugins by default, making it extremely full-featured."