View comments | RSS feed

Tween class

Inheritance (Root class)

ActionScript Class Name mx.transitions.Tween

The Tween class lets you use ActionScript to move, resize, and fade movie clips easily on the Stage by specifying a property of the target movie clip to be tween animated over a number of frames or seconds. The Tween class also lets you specify a variety of easing methods. Easing refers to gradual acceleration or deceleration during an animation, which helps your animations appear more realistic. For example, the options on a drop-down list component you create might gradually increase their speed near the beginning of an animation as the options appear, but slow down before the options come to a full stop at the end of the animation as the list is extended. Flash provides many easing methods that contain equations for this acceleration and deceleration, which change the easing animation accordingly.

The Tween class also invokes event handlers so your code may respond when an animation starts, stops, or resumes or increments its tweened property value. For example, you can start a second tweened animation when the first tween invokes its Tween.onMotionStopped event handler, indicating that the first tween has stopped.

Method summary for the Tween class

The following table lists methods of the Tween class:

Method

Description

Tween.yoyo()

Instructs the tweened animation to continue from its current value to a new value.

Tween.fforward()

Forwards the tweened animation directly to the end of the animation.

Tween.nextFrame()

Forwards the tweened animation to the next frame.

Tween.prevFrame()

Directs the tweened animation to the frame previous to the current frame.

Tween.resume()

Resumes a tweened animation from its stopped point in the animation.

Tween.rewind()

Rewinds a tweened animation to the beginning of the tweened animation.

Tween.start()

Starts the tweened animation from the beginning.

Tween.stop()

Stops the tweened animation at its current position.

Tween.toString()

Returns the class name, "[Tween]".

Tween.yoyo()

Instructs the tweened animation to play in reverse from its last direction of tweened property increments.

Property summary for the Tween class

The following table lists properties of the Tween class.

Property

Description

Tween.duration

The duration of the tweened animation in frames or seconds. Read-only.

Tween.finish

The last tweened value for the end of the tweened animation. Read-only.

Tween.FPS

The number of frames per second of the tweened animation. Read-only.

Tween.position

The current value of the target movie clip's property being tweened. Read-only.

Tween.time

The current time within the duration of the animation. Read-only.

Event handler summary for the Tween class

The following table lists event handlers of the Tween class.

Event

Description

Tween.onMotionChanged

Event handler; invoked with each change in the tweened object's property that is being animated.

Tween.onMotionFinished

Event handler; invoked when the Tween object finishes its animation.

Tween.onMotionResumed

Event handler; invoked when the Tween.resume() method is called, causing the tweened animation to resume.

Tween.onMotionStarted

Event handler; invoked when the Tween.start() method is called, causing the tweened animation to start.

Tween.onMotionStopped

Event handler; invoked when the Tween.stop() method is called, causing the tweened animation to stop.


Version 8

Comments


dtotal said on Oct 5, 2005 at 9:46 AM :
This first method in this class should be:

Tween.continueTo(finish:number, duration:number)
nowB@ said on Oct 18, 2005 at 11:47 AM :
why is this class documented under "components lang ref" and not under "actionscript classes" ?
what about documenting the constructor ? params ? etc
jdehaan said on Oct 20, 2005 at 10:32 AM :
This class is documented here because it was created in order to facilitate Screens tweening, and animate components. The fact it can be used with movie clips (and so on) is a nice "bonus" feature. And hence, why it is in the components language reference.

The constructor and parameters are documented. Please press the "next" button at the top of your page where you'll find those details and links to the full API reference.
madgett said on Dec 13, 2005 at 10:35 PM :
A nice undocumented property of the Tween class:

mytween.isPlaying

Returns a boolean value (true/false), true if playing false otherwise. This is necessary when you are running tween's based on MovieClip events such as onRollOver/onRollOut and prevents tweens from overlapping or cutting out while they are moving away from the mouse pointer.
GalaxyBeing said on Jan 31, 2006 at 5:13 PM :
On this page it say Tween.FPS is read only but if you go to the page about Tween.FPS it says you can set it. In fact, it says it will return undefined unless it is set explicitly, so it's actually sort of write only, at first ;-)
bigblowfish said on Feb 23, 2006 at 9:52 PM :
It doesn't seem to be stated if this is available for FP7 or only FP8.

I'm using Flash 8, but need to compile down to 7, is this possible?
No screen name said on Feb 24, 2006 at 6:01 AM :
/*
version 1.3
-------------------------------------
DESCRIPTION:
-------------------------------------

Extended tween function contains:
-standard tween function pack
-bezier tween
-colorRGB tween
-color tween

-------------------------------------
USAGE:
-------------------------------------

function BezierTween(obj, prop, begin, finish, duration, useSeconds, a_val, b_val);

obj: reference - the object which the Tween targets
prop: string - name of the property (in obj) that will be affected
begin: number - the starting value of prop
finish: number - the starting value of prop
duration: number - the length of time of the motion
useSeconds: boolean - a flag specifying whether to use seconds instead of frames
a_val = control point A's value
b_val = control point B's value

-------------------------------------
EXAMPLE: "bezier"
-------------------------------------
//Create a new FLA. Copy this Class file into same folder as FLA.
//Create a movieclip on stage with name "mc".
//Put this code in frame 1.

import mx.transitions.*;
import mx.transitions.easing.*;
import tween.TweenEx;

twnBezX = new TweenEx(mc, "bezier_x",null, 0, 300, 30, false, true,100, 400);
twnBezY = new TweenEx(mc, "bezier_y",null, 0, 300, 30, false, true,100, 400);

twnBezX.start();
twnBezY.start();


-------------------------------------
USAGE:
-------------------------------------

function colorTween(obj, prop, begin, finish, duration, useSeconds, [optional]b_val);

obj: reference - the object which the Tween targets
prop: string - name of the property (in obj) that will be affected
begin: number - the starting value of prop
finish: number - the starting value of prop
duration: number - the length of time of the motion
useSeconds: boolean - a flag specifying whether to use seconds instead of frames
b_val = applied to photo "mc" | hole object


-----------------------------------------------
EXAMPLE: "redOffset","greenOffset","blueOffset","alphaOffset"
-----------------------------------------------
//Create a new FLA. Copy this Class file into same folder as FLA.
//Create a movieclip on stage with name "mc".
//Put this code in frame 1.

import mx.transitions.*;
import mx.transitions.easing.*;
import tween.TweenEx;

var colorTrans:ColorTransform=new ColorTransform;
var twnRedColor:TweenEx = new TweenEx(mc, "redOffset",null, 0,255 , 10, true,true,true);
twnRedColor.start();
"or"
var twnAlphaEx:TweenEx = new TweenEx(mc, "alphaOffset",null, 10,100 , 10, true,true,true);
twnAlphaEx.start();

-------------------------------------
USAGE:
-------------------------------------

function colorTween(obj, prop, begin, finish, duration, useSeconds, [optional]b_val);

obj: reference - the object which the Tween targets
prop: string - name of the property (in obj) that will be affected
begin: number - the starting value of prop
finish: number - the starting value of prop
duration: number - the length of time of the motion
useSeconds: boolean - a flag specifying whether to use seconds instead of frames
b_val = applied to photo "mc" | hole object


-----------------------------------------------
EXAMPLE: "RGB"
-----------------------------------------------
//Create a new FLA. Copy this Class file into same folder as FLA.
//Create a movieclip on stage with name "mc".
//Put this code in frame 1.

import mx.transitions.*;
import mx.transitions.easing.*;
import tween.TweenEx;

var colorTrans:ColorTransform=new ColorTransform;
var twnRedColor:TweenEx = new TweenEx(mc, "rgb",null, 32,255 , 10, true,true);
var twnGreenColor:TweenEx = new TweenEx(mc, "rgb",null, 45,255 , 15, true,true);
twnRedColor.start();
twnGreenColor.start();

-------------------------------------
CREDITS:
-------------------------------------
BezierTween Class extension to TweenEx by Felix Turner (www.airtightinteractive.com)
Bezier Tween function by Robert Penner (www.robertpenner.com)
TweenEx Class by Winx (www.winx.ws)
Tween Class by Macromedia

*/
jdehaan said on Feb 24, 2006 at 2:54 PM :
See each API entry about which is the lowest Flash Player supported (for example, see http://livedocs.macromedia.com/flash/8/main/00004167.html for such details). The individual entries will tell you the support for each method, property, etc).
No screen name said on Feb 26, 2006 at 11:40 PM :
class tween.TweenEx extends Tween
{
var trans:Transform;
var colorTrans:ColorTransform;
var colorRGB:Object;
var exParam1;
var exParam2;
var extended:Boolean;
var currentMovie;
var propObject:Object;


public var begin:Object;//change
public var change:Object;//change
public var prevPos:Object;//change
private var op:OperatorsEx;//change
private var _pos:Object; //change

//////////////////////////////////////////////////////
// CONSTRUCTOR
//////////////////////////////////////////////////////
function TweenEx(obj:Object, prop:String, func:Function, begin, finish, duration:Number, useSeconds:Boolean,extended:Boolean,exParam1,exParam2)
{
this.extended=extended;
op=new OperatorsEx();
//classObject=this;

this.currentMovie=MovieClip(obj);
if(!extended || extended==undefined)
stdTween(obj, prop, func, begin, finish, duration, useSeconds);
//super.Tween(obj, prop, func, begin, finish, duration, useSeconds); //should but won't???
else
exTween(obj, prop, func, begin, finish, duration, useSeconds,extended,exParam1,exParam2);//

}
//////////////////////////////////////////////////////









//////////////////////////////////////////////////////
// stdTween-same as in Tween class (without imm start)
//////////////////////////////////////////////////////
function stdTween (obj, prop, func, begin, finish, duration, useSeconds) {

OnEnterFrameBeacon.init();
if (!arguments.length) return;
this.obj = obj;
this.prop = prop;
this.begin = begin;
this.position = begin;
this.duration = duration;
this.useSeconds = useSeconds;
if (func) this.func = func;//std
this.finish = finish;
this._listeners = [];
this.addListener (this);
//this.start(); //it is logical to start when you want not when you create instanace
}
//////////////////////////////////////////////////////


//////////////////////////////////////////////////////
// exTween-switch function
//////////////////////////////////////////////////////
function exTween(obj:Object, prop:String, func:Function, begin, finish, duration:Number, useSeconds:Boolean,extended:Boolean,exParam1,exParam2)
{
switch(prop)
{
case "alphaOffset":
case "redOffset":
case "greenOffset":
case "blueOffset":
colorTween(obj, prop, func, begin, finish, duration, useSeconds,exParam1)//exParam2,
break;
case "bezier_x":
case "bezier_y":
bezierTween (obj, prop.slice(-2) , begin, finish, duration, useSeconds,exParam1,exParam2) ;
break;
case "rgb":
colorRGBTween(obj, prop, func, begin, finish, duration, useSeconds)//clrTrans,
break;
}
}

//////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
function colorTween(obj, prop, func, begin, finish, duration, useSeconds,bPhoto:Boolean)//clrTrans,
{
var b,f;
OnEnterFrameBeacon.init();
if (!arguments.length)
{
return;
}

if(isNaRGB(begin) || isNaRGB(finish))
return;

if(prop=="alphaOffset")//for those are customized to 0-100% alpha value
{
b=finish;
f=begin;
begin=-b*2.55;
finish=-f*2.55;
}

colorTrans=new ColorTransform;
colorTrans["alphaMultiplier"]=1; //object must be visible
if(bPhoto)
{

colorTrans[prop.slice(0,-6)+"Multiplier"]=1;
//colorTrans[prop]=0;//begin
}
else
{
colorTrans.blueMultiplier=0;
colorTrans.redMultiplier=0;
colorTrans.greenMultiplier=0;
colorTrans.blueOffset=0;
colorTrans.redOffset=0;
colorTrans.greenOffset=0;
colorTrans[prop.slice(0,-6)+"Multiplier"]=0;

}

///////////////////////
//init
//
trans = new Transform(MovieClip(obj));

this.obj =colorTrans;//.colorTransform
this.prop =prop;//
this.begin = begin;
this.position = begin;
this.duration =duration;
this.useSeconds = useSeconds;
if (func) this.func = func;
this.finish =finish;
this._listeners = [];
this.addListener(this);
//this.start(); why to start immidiatly????
}
//////////////////////////////////////////////////////




//////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
function colorRGBTween(obj, prop, func, begin, finish, duration, useSeconds)//clrTrans,
{

OnEnterFrameBeacon.init();
if (!arguments.length) return;


//custom properties
propObject=new Object();
propObject.redOffset=0;
propObject.blueOffset=0;
propObject.greenOffset=0;

//init
trans = new Transform(MovieClip(obj));
//trans.colorTransform=rgbObject(begin);

this.obj = trans;
this.prop = "colorTransform";
this.begin = rgbObject(begin);
this.position = rgbObject(begin);
this.duration = duration;
this.useSeconds = useSeconds;
if (!func) this.func = rgbTween;
else this.func=func; //out side func must return colorTransform Object
this.finish = rgbObject(finish);
this._listeners = [];
this.addListener (this);

//this.start(); why to start imm????
}
//////////////////////////////////////////////////////


//////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
function bezierTween (obj, prop, begin, finish, duration, useSeconds,point1,point2) {
OnEnterFrameBeacon.init();
if (!arguments.length) return;
this.obj = obj;
this.prop = prop;
this.begin = begin;
this.position = begin;
this.duration = duration;
this.exParam1 = point1;
this.exParam2 = point2;
this.useSeconds = useSeconds;
this.func = tweenCubicBez;
this.finish = finish;
this._listeners = [];
this.addListener (this);
//this.start(); why to start imm????
}

//////////////////////////////////////////////////////
// Cubic Bezier tween from b to b+c, influenced by p1 & p2
// t: current time, b: beginning value, c: total change, d: duration
// p1, p2: Bezier control point positions
//////////////////////////////////////////////////////:Number
static function tweenCubicBez (t:Number, b, c, d,p1:Number,p2:Number) {
return ((t/=d)*t*c + 3*(1-t)*(t*(p2-b) + (1-t)*(p1-b)))*t + b;
}
//////////////////////////////////////////////////////


function std(t, b, c, d)
{
return c*t/d + b;
};
//////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
function rgbTween(t, b, c, d):ColorTransform
{
var prop,clrTrans:ColorTransform=new ColorTransform();
for(prop in this.propObject)
{
//if(prop.slice(-10))
clrTrans[prop]=c[prop]*t/d+b[prop];
}

return clrTrans;
}
Winx Alex said on Mar 21, 2006 at 4:11 AM :
More about TweenEx u can find on:

http://www.flashkit.com/tutorials/Actionscripting/Expert/Extendin-Winx-1322/index.php
jfhoff said on May 26, 2008 at 5:16 AM :
Are there any other undocumented properties/methods/events besides "isPlaying"? I need a way to identify the MovieClip upon which the Tween that owns the current event handler is operating. The event handler is common to a set of Tweens, and it doesn't know which one it is. The "this" global property identifies the Tween, but that's as far as I can get.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00004142.html