PDA

View Full Version : Mouse follow + ease + restrictions



buddylee
February 25th, 2003, 10:06 PM
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...



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...

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?

Guig0
February 26th, 2003, 09:58 AM
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:



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?

buddylee
February 26th, 2003, 02:46 PM
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

Guig0
February 26th, 2003, 02:49 PM
=)

buddylee
February 26th, 2003, 05:59 PM
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.