# Constant rate of motion via script

**URL:** <https://forum.kirupa.com/t/constant-rate-of-motion-via-script/9084>\
**Category:** Uncategorized\
**Created:** [December 4, 2002, 4:11pm UTC](https://forum.kirupa.com/t/constant-rate-of-motion-via-script/9084 "2002-12-04T16:11:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendry](https://avatars.discourse-cdn.com/v4/letter/h/ac91a4/32.png) [@hendry](https://forum.kirupa.com/u/hendry)\
**Post date:** [December 4, 2002, 4:11pm UTC](https://forum.kirupa.com/t/constant-rate-of-motion-via-script/9084/1 "2002-12-04T16:11:56Z")

</div>

I’m tyring to get a movie clip to move from it’s current x, y  
position to a designated x., y postion specified  
in a button (onrelease).  
But I need the movie clip to move at a constant rate regardless  
of it’s distance traveled.  
I can’t get it to work.  
I’m having troble knowing which code to put where,  
Button, object and frame.  
Can anyone help?

---

<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:** [December 4, 2002, 4:35pm UTC](https://forum.kirupa.com/t/constant-rate-of-motion-via-script/9084/2 "2002-12-04T16:35:00Z")

</div>

code for the button:

```php
on (press){
   pathToTheMovieclip.gotoAndStop (2);
}
on (release){
   pathToTheMovieclip.gotoAndStop (1);
}

```

[SIZE=1]note: the **pathToTheMovieclip** should look like that (example of a mc called ball on the main timeline) \_root.ball[/SIZE]

On the mc:

1- create two identical frames;  
2- on the second one place this code:

```php
this.onEnterFrame = function(){
	speed=3;
	this._y+=speed;
}

```

[SIZE=1]note: **speed** variable could be set to any value you want, the **\_y** is for vertical movement, if you want to move horizontally use **\_x** [/SIZE]

=)
