Apr 10, 2007

Make an object follow the mouse...

Example : Mouse follower

Ok, first we start by drawing a circle 50 x 50, it's instance name should be "circle"
after you finish drawing your circle go to Scene 1 Frame 1 and add this code to the frame:

onEnterFrame = function () {
circle._x = _xmouse ;
\\here we are setting the circle position to the x position of the mouse, remember that flash \\uses coordinates for setting positions
circle._y = _ymouse ;
\\we close the function, what we made here is we set the circle position to the mouse position, \\and the onEnterFrame means this code will repeat every time you pass through this frame

Ok, you can use this code for many things, such as making a crosshair for a game or make an interactive animation. And remember if you want to hide the mouse you should add this to the code

Mouse.hide() ;

this code goes right before all the code.
Remember for a better animation set Frames per second to 25 or higher...
Hope you find this usefull.


1 comment:

EagleVision said...

This is very useful, thank you.

PS: Would it be ok if you let me Copy/Paste it to my blog? Thank you. you have great tuts! :D


Kevin Stubbs, Ivan Alvarez Malo