Using the class Tween and TweenExtended

The ActionScript offers ways to develop extremely powerful dynamic animations without using timeline. It has diverse classrooms of the proper Flash and others developed by third.
O Action Script oferece meios de desenvolver animações dinâmicas extremamente poderosas sem usar a timeline. Há diversas classes do próprio Flash e outras desenvolvidas por terceiros. Amongst that more I use this the Tween and the TweenExtended. It sees as to utlizar the Tween class in this article in the site Kirupa.

Class TweenExtended
Before initiating make the download the last version of the TweenExtended class in the site
http://www.sqcircle.com/downloads/ and installs for Macromedia Extension Manager. After the installation must appear a new option in help of the Flash.
The syntax of the class is the following one:

[as]import mx.transitions.easing.*;
import mx.transitions.TweenExtended;
var _tween = new TweenExtended(target, props, easeFunc, strt, end, dur, useSecs, bezierPoint1, bezierPoint2);
/*
constructor for Tween Exdended class
target: reference – the object which the Tween targets
props: array – names of the properties (in obj) that will be affected
easeFunc: function – the type of easing equation to be used [import easing equations: import mx.transitions.easing.*;]
strt: array – the starting value of props
begin: array – the ending value of props
dur: number – the length of time of the motion; set to infinity if negative or omitted
useSecs: boolean – a flag specifying whether to use seconds instead of frames

*optional bezier parameters*
To use the Bezier tween both parameters must be entered and must be used in conjunction with mx.transitions.easing.Bezier;
has three easing methods: tweenQuadBez, tweenQuadBezThru, tweenCubicBez

bezierPoint1: number – numerical x position value
bezierPoint2: number – numerical y position value
*/[/as]

We go to see some examples:
It creates a new archive in the Flash, later creates one movieclip (a ball for example) giving the name of instance of “ball_mc”. Example with metodo TweenExtended.continueTo ():

[as]import mx.transitions.easing.*; // optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
var _tween:TweenExtended = new TweenExtended(ball_mc, [“_x”,”_y”,”_alpha”], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
_tween.onMotionFinished = function(obj) {
_tween.continueTo([150, 50, 90],5);
}
[/as]
It sees the example working.

Example with method TweenExtended.yoyo():
[as]
import mx.transitions.easing.*; // optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
var _tween:TweenExtended = new TweenExtended(ball_mc, [“_x”,”_y”,”_alpha”], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
_tween.onMotionFinished = function(obj) {
_tween.yoyo();
}[/as]

It sees the example working

Example with method TweenExtended.addListener():

[as]
import mx.transitions.easing.*;
// optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
//
// EventListener Object:
var eventListener:Object = new Object();
eventListener.onMotionStarted = function(obj) {
trace(obj.obj+” – onMotionStarted – eventListener”);
};
eventListener.onMotionFinished = function(obj) {
trace(obj.obj+” – onMotionFinished – eventListener”);
};
//
//
var _tween:TweenExtended = new TweenExtended(ball_mc, [“_x”, “_y”, “_alpha”], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
// register the listener:
_tween.addListener(eventListener);[/as]

It sees the example working

Example with method TweenExtended.loop:

[as]import mx.transitions.easing.*;
// optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
var _tween:TweenExtended = new TweenExtended(ball_mc, [“_x”, “_y”, “_alpha”], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
_tween.loop = true;
//
_tween.onMotionLooped = function(obj) {
trace(obj.obj+” – onMotionLooped”);
};[/as]

It sees the example working.

Another sufficiently interesting class is the TransitionManager of the proper Flash. With it we can create transistions saw ActionScript and with effect that a certain time would take to make for timeline. We go to see an example of as to use the TransitionManager class the same using movieclip “ball_mc” used in the examples above:

[as]mx.transitions.TransitionManager.start(ball_mc, {type:mx.transitions.Zoom, direction:mx.transitions.Transition.IN, duration:1, easing:mx.transitions.easing.Bounce.easeOut}); [/as]

It sees the example working.

Documentation of classe TransitionManager
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00004085.html

Classe Tween
http://www.kirupa.com/developer/actionscript/tween.htm

Classe Tween Extended
http://www.sqcircle.com/downloads/

Using the Tween and Transition Classes in Flash MX 2004
http://www.macromedia.com/devnet/flash/articles/tweening.html

Was this article helpful? feel free to make a donation and help keep the blog in the air
Flash

Leave a Reply