PDA

View Full Version : funky tweening


kalpaitch
01-20-2009, 01:48 PM
I am familiar with the actionscript tween class. But what is the easiest way to make a box tween on two paths. For example first it moves from on the x axis by +100 and then once that has finished it moves on the y axis +100. I know Flash CS4 allows customing tweening, but does this respond to actionscript commands?

RefreshGFX
01-20-2009, 03:21 PM
In answer to your question - using the actionscript tween class... You could "listen" for the "x" motion to finish animating then play the "y" animation. It would be something like...

// Combine tween on a MovieClip
function animTween(){
var mc_x:Tween = new Tween( mc_name, "_x", easeType, begin, end, time, true);

// Then listen for finished animation event handler

mc_x["onMotionFinished"] = function(){
// do something
}
};

// ------- HOWEVER, I find that to be a pain-in-the-butt ... SO ... ------

You should look into mc_teen.as or Tweener (google those). Although, Tweener is more recent and advanced - I use mc_tween. With that I can set a delay for the animation to happen when entering the frame - or - I can set a callback function.

So, for instance with the time delay I can tell a movie-clip to move 100 pixels on the _x path in 0.5 second and to start the animation 5 seconds after entering the frame. Then, I can tell the same movie-clip to move 100 pixels on the _y axis in 3 seconds. But, not to start that animation for 5.5 seconds (which would be the time it took for the _x animation to complete.

An Example of using time delay with mc_tween.as would be:

// mc_instance_name.slideTo(x, y, seconds, animation type, delay, callback, extra1, extra2);

// Example...

// this animation will start 5 seconds after entering the frame and last for 0.5 tenths of a second...
mc_instance_name.slideTo(100, null, 0.5, easeInQuad, 5.0);

// this animation won't start for 5.5 seconds - enough time for the above one to complete
mc_instance_name.slideTo(null, 100, 3, easeInQuad, 5.5);

Alternatively, I could be more precise and use a call-back function on the _x animation. Similar to using the actionscript tween class - the callback function in mc_tween will be called only when I tell it. For example...

// mc_instance_name.slideTo(x, y, seconds, animation type, delay, callback, extra1, extra2);

mc_instance_name.slideTo(100, null, 0.5, easeInQuad, 5.0, endANIMATION);

function endANIMATION() {
mc_instance_name.slideTo(null, 100, 3, easeInQuad);
// In the above I don't need to put a 5.5 second delay. As this animation won't start until the callback is "called" - once that happens - I want it to play immediately.
}

That's it. Good luck with it.