Okay, this is my first try at an Action Script lesson, but I hope you learn something from it. I'm going to show you how to make a movie clip follow your mouse, and no, this is not a startDrag("")/stopDrag tutorial!
Start off by making a movie clip, call it anything you want. Drag it out on stage.
Click on it, make sure it says Actions - Movie Clip on the actions bar. If it does, open the actions bar up.
Start the code off by putting:
onClipEvent(enterFrame){your code will go here }
The onClipEvent(enterFrame) is telling flash, when the movie clip loads up onto the frame, the code in the braces will happen. The braces are essential, or the code will not work, as you might already know.
Okay, so let's add on a little more.
onClipEvent(enterFrame){this._x = (_root._xmouse)}
this._x = (_root.xmouse) is telling flash that the movie clip will horizontally follow the mouse, almost like an automatic slidebar.
Now let's add some more.
onClipEvent(enterFrame){this._x = (_root.xmouse);
this._y = (_root.ymouse); }
The code that I just added is exactly like the previous code but now the Mc will follow the mouse vertically as well. Making it a perfect dragged movie clip.
If you want to make it kinda like runescape movement where your mouse goes to a spot when you click on it, you can, just change the clip event to mouseDown.
onClipEvent(mouseDown){this._x = (_root.xmouse);
this._y = (_root.ymouse); }
You can really make some funky stuff happen if you experiment with it. Try out some of these codes.
onClipEvent(enterFrame){this._y= (_root.xmouse);
}
onClipEvent(enterFrame){this._x = (_root.ymouse);
}
It's like a slide bar, but the mc is following the _ymouse with a _x motion and vice-versa.
Good Luck!