# Smoot movement using scripts

**URL:** <https://forum.kirupa.com/t/smoot-movement-using-scripts/20675>\
**Category:** Uncategorized\
**Created:** [May 12, 2003, 6:26am UTC](https://forum.kirupa.com/t/smoot-movement-using-scripts/20675 "2003-05-12T06:26:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![catreya](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@catreya](https://forum.kirupa.com/u/catreya)\
**Post date:** [May 12, 2003, 6:26am UTC](https://forum.kirupa.com/t/smoot-movement-using-scripts/20675/1 "2003-05-12T06:26:59Z")

</div>

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

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

[/AS] :hair:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 12, 2003, 6:36am UTC](https://forum.kirupa.com/t/smoot-movement-using-scripts/20675/2 "2003-05-12T06:36:39Z")

</div>

see this:

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 12, 2003, 7:39am UTC](https://forum.kirupa.com/t/smoot-movement-using-scripts/20675/3 "2003-05-12T07:39:27Z")

</div>

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

[AS]

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;
}
}

```

}  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 12, 2003, 7:43am UTC](https://forum.kirupa.com/t/smoot-movement-using-scripts/20675/4 "2003-05-12T07:43:09Z")

</div>

did i mention before that this is a button and not a movie clip!!!
