# Mouse follow + ease + restrictions

**URL:** <https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433>\
**Category:** flash\
**Created:** [February 26, 2003, 3:06am UTC](https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433 "2003-02-26T03:06:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![buddylee](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@buddylee](https://forum.kirupa.com/u/buddylee)\
**Post date:** [February 26, 2003, 3:06am UTC](https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433/1 "2003-02-26T03:06:23Z")

</div>

Ok, this should be simple for you guys. Here is what I am trying to do:  
I have this box which is a MC and it is called “orangebox”.  
Now I want this box to follow my mouse, but only over a certain region. I put a rectanlge MC over the area I want the box to follow. On that rectange I put this code…

```php

on (rollOver) {
	startDrag("_root.orangebox", true, 60, 362, 742, 362);
}

```

That works fine and dandy, but I want it to ease when it follows, not stay on the mouse. I think it will give it a cooler look. The code Kirupa has for ease is…

```php
onClipEvent (load) {
	_x = 0;
	_y = 0;
	speed = 5;
}
onClipEvent (enterFrame) {
	endX = _root._xmouse;
	endY = _root._ymouse;
	_x += (endX-_x)/speed;
	_y += (endY-_y)/speed;
}

```

I need to get these two codes together. Any takers?

---

<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:** [February 26, 2003, 2:58pm UTC](https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433/2 "2003-02-26T14:58:05Z")

</div>

that´s easy, but let me get this straight: you want the mc to follow the mouse only horizontally, right?

if so, use this code:

```auto

onClipEvent (load) {
    _x = 0;
    _y = 0;
    speed = 5;
}
onClipEvent (enterFrame) {
    endX = _root._xmouse;
    _x += (endX-_x)/speed;
	if (this._x<60){
		this._x=60;
	}
	if (this._x>742){
		this._x=742;
	}
}

```

note that i removed the _endY = \_root.\_ymouse;_ and the _\_y += (endY-\_y)/speed;_, coz that way the mc won´t follow the mouse vertically (y = vertical axis, and x= horizontal axis). And also, i put a couple of IFs to check if the mc whent over the desired spot, and if it does it will stop.

is that it?

---

<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:** [February 26, 2003, 7:46pm UTC](https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433/3 "2003-02-26T19:46:07Z")

</div>

looks like it will work, will have to try it when I get home in about 2 hours. Thanks a lot man. I will post if I have any problems

---

<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:** [February 26, 2003, 7:49pm UTC](https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433/4 "2003-02-26T19:49:44Z")

</div>

=)

---

<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:** [February 26, 2003, 10:59pm UTC](https://forum.kirupa.com/t/mouse-follow-ease-restrictions/14433/5 "2003-02-26T22:59:04Z")

</div>

Thank you Guig0, it works to perfection.  
I also added an on (rollOver) so it only follows when I roll over the buttons. Thanks a lot bro.
