If you're not using the Tween Class that flash provides, today is a great day to start. ESPECIALLY if your code looks something like this:
-
oldBustedTween(350);
-
-
function oldBustedTween(val:Number)
-
{
-
this.onEnterFrame = function()
-
{
-
if(Math.abs(myShape._x - val)<1)
-
{
-
myShape._x = val;
-
this.onEnterFrame = null;
-
}
-
else
-
{
-
myShape._x += (val - myShape._x)*.2;
-
}
-
}
-
}
At least this is how I used to move objects around. Today, and for the past several years you have had the Flash Tween Class available to you. It does all the work as you see above only it is much simpler to read.
After creating a new flash document follow these steps:
1) Create a shape and make it into a movieclip
2) Give your movieClip an instance name of myShape
3) Add this actionscript to frame 1
-
import mx.transitions.easing.*;
-
import mx.transitions.Tween;
-
-
myAwesomeTween(350)
-
-
function myAwesomeTween(val:Number)
-
{
-
var myTween = new Tween(myShape, "_x", Strong.easeOut, myShape._y, val, .9, true);
-
}
4) Save and test your movie.
Not too shabby right!
Basically the tween class is taking in all the information you give it and running all the calculations for you. Here is a closer look at each part.
From the help docs it looks like this :
Tween( obj:Object, prop:String, func:Function, begin:Number, finish:Number, duration:Number, useSeconds:Boolean )
My longer version:
1) Name of movieClip instance
Such as myShape
2) What do you want me to do
_x - _y - _alpha
3) When I do it what kind of effect
Use - Strong.easeOut / Regular.easeOut / Strong.easeIn etc.
4) Where do you want me to start
Use a number
5) Where do you want me to end up
Use a number
6) How fast in seconds or frames (see 7)
Use a number such as .5 or 10
7) Use seconds (if you put false it will assume you are counting in frames instead of seconds)
true or false
var myTween = new Tween(1, 2, 3, 4, 5, 6, 7)
-
var myTween = new Tween(myShape, "_x", Strong.easeOut, myShape._y, val, .9, true);
Once you start using the Tween class you will never go back. It is one of the easiest ways to get things to move. It also has ton's of other cool features to get the effects you want. Test out out.
Check out this site for a more in depth discussion of the Tween Class.

0 Response to “You and a Tween should get a room!”