Mouse Cursor Followers

Out of curiousity…how would one go about making a mouse cursor follower in Flash MX, if one was so inclined??

:trout:

There are tons of tutorials on this site about it.

The flash 5 method of it is the same as the mx method btw.

IF one was so inclined? Do people still get inclined? I suppose they do :wink:

heres what Ill suggest:


onClipEvent(load){
	Mouse.hide();
}
onClipEvent(mouseMove){
	_x = _parent._xmouse;
	_y = _parent._ymouse;
	updateAfterEvent();
}
onClipEvent(unload){
	Mouse.show();
}

common questions:
You’re using MX, why not use onEnterFrame?
this keeps the code specific to the cursor clip. Lets say suddenly you decide you dont want a custom cursor anymore. Using this code, you just delete your cursor and its done, otherwise you might need to hunt down the code which controls it. Plus it keeps the code easily accessible from with that scope (instead of hiding it within the cursor clip itself)

MouseMove?
This only positions the mouse when the mouse moves. If the mouse isnt moving, no point in moving the cursor to be exactly where it already is (as would happen with enterFrame)

_parent._xmouse? Why not _root?
_root._xmouse/_root._ymouse would only work if your clip is IN _root, otherwise, you better hope that if you cursor clip is in another clip, that clip better be at position 0,0 in _root or your cursor will be offset and just plain off. No matter where this clip is here (even if this swf is loaded into another movieclip from another movie) _parent._xmouse will always reference the right one.

updateAfterEvent-whosawha?
This updates the position of the mouse indeoendant of the frame rate of your movie. This means that your cursor doesnt just move 12 times a frame (when the movie is set at a frame rate of 12 frames a second) but rather everytime the mouse moves on the screen despite the fact that the swf hasnt yet had time to draw another frame based on the frame rate. This means your mouse might move 30 postions in 12 actual frames. You get a much smoother cursor in doing this.

Thanks for the description Sen. I had to go soon so I didn’t have time to say much. Actually, I have to go now… 'DOH!

Laters.