PDA

View Full Version : smoot movement using scripts



catreya
May 12th, 2003, 02:26 AM
i am newbie around in flash. i have written a code for move an object (button instance). but my problem is its instantaneous. i want it to move in a smooth motion (something like tweening). i have tried for loops and stuff... but i have not been able to smoothen the motion.

the code is as follows


on (rollOver) {
speed = 2;
finalx = contactbutton._x + 100;
finaly = contactbutton._y + 100;
contactbutton._x += (finalx - contactbutton._x)/speed;
}

:hair:

ahmed
May 12th, 2003, 02:36 AM
see this:

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=21149&highlight=easing

catreya
May 12th, 2003, 03:39 AM
i checked out the link and made modifications to the script. i'm placing my script below: actually, i have tried using 'easing' only the x values for a start



on (rollOver) {
/ get original x and y position /
xpos = this.contactbutton._x;
ypos = this.contactbutton._y;
speed = 3;
/calculate final x & y position /
finalX = xpos + 100;
finalY = ypos + 100;

onEnterFrame = function() {
differenceX = finalX - this.contactbutton._xscale;
differenceY = finalY - this.contactbutton._yscale;
if (Math.floor(differenceX == 0)) {
delete.this.onEnterFrame;
} else {
contactbutton._xscale += differenceX /speed;
}
}
}

catreya
May 12th, 2003, 03:43 AM
did i mention before that this is a button and not a movie clip!!!