Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : Mc Folling Mouse



Patrick
2/18/2006 7:59:14 PM
that is cool

[quoted text, click to view]

Ross111
2/18/2006 11:37:25 PM
Hi There,

I've made a simple mc that follows the cursor using this code:

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

all is simple but i'm wondering if anyone knows how to make the mc goto
specific coordinates when it rolls over something like on this guys website:
http://www.kazsh.com/...

Help is greatly appreciated... Thanks
kglad
2/19/2006 12:03:42 AM
Ross111
2/19/2006 12:15:08 AM
Sorry, I dont think i was too clear in my question, i want the mc to follow the
mouse then when i roll over a button, i want the mc to goto specific
coordinates, then when i roll out, the mc should follow the mouse again...

if you did know what i was meaning, it didn't work...

thanks for your help anyway !
NSurveyor
2/19/2006 12:35:57 AM
Instead of using that code... give your clip the instance name, clip. Then,
place this code on the frame it resides on:

clip.onEnterFrame = function(){
if(!this.rolled){
this.gx = _xmouse;
this.gy = _ymouse;
var speed = 10; //speed for following mouse
}else{
var speed = 2.5;//speed for jumping to position
}
this._x+= (this.gx-this._x)/speed
this._y+= (this.gy-this._y)/speed;
}

and then for each button you would need something like:

SOME_BUTTON.onRollOver = function() {
clip.rolled = true;
clip.gx = this._x;
clip.gy = this._y;
this.onRollOut = function() {
clip.rolled = false;
};
};

which can be accomplished for multiple instances using a for loop.
Ross111
2/19/2006 12:53:54 AM
NSurveyor
2/19/2006 12:57:52 AM
AddThis Social Bookmark Button