PDA

View Full Version : How do you 'step' an animation, but ease it, too?


dave123williams
04-06-2006, 10:47 PM
Hey all;

I have kind of a sticky wicket that I'm trying to figure out - it's really driving me nuts, so any help you can offer is greatly appreciated.

Ok - so I have this animation:

http://dave.hero.com/masked.html

It's masked and tweening/easing nicely. Here's the code I'm using to do it:

onClipEvent (load) {
_root.targX = 457;
}

onClipEvent (enterFrame) {
cX = this._x;
difX = cX-_root.targX;
setProperty(this, _x, cX-(difX/10));
}


However, I'd like it to behave more like this:

http://dave.hero.com/masked3.html

I cobbled this second animation together manually, just keyframing everything so that the blue dots step from keyframe to keyframe. For the life of me, I can't figure out how to get it to step from position to position with the same smoothness you'd get from using a function to describe the animation.

I'm not nearly enough of an AS expert to figure this one out, so any advise/assistance/suggestions are most appreciated!

:confused:

Dylan Marvin
04-08-2006, 04:54 AM
Interesting problem!
My way is one of many solutions. There are probably some interval-junkies out there that could make a cleaner version. I tried it with a "for" statement, but it got too code heavy--this was the simplest thing I could come up with.
Anyway, it works in the attachment, you'd have to tweak it for your purposes:
onClipEvent (load) {
//set initial _x
_x = 100;
//the "counter", the Flash nerd's favorite tool (often called "i"):
counter = 0;
//Here's the best part, we'll increase the timer to increase to sim. easing:
timer = 2.5;
//Here's the "_x" value at which we say "stop":
limit = 425;
}
onClipEvent (enterFrame) {
//do "this" while _x is below the limit:
if (_x<limit) {
//If a certain point in time is reached:
if (counter>=timer) {
//Move the Clip
_x += 25;
//reset the counter:
counter = 0;
//increase the time delay by small, multiple amount ("+" wouldn't ease, use "*") tweak this number to set your easing:
timer *= 1.1;
}
//increase the counter by one and start it all over again:
counter++;
}
}