Main Content
Custom Cursors
Welcome to Foundation Flash's tutorials. In this tutorial, we are going to make a custom cursor in Flash. What we will make will look like this:
Pretty good, eh? Well, let's get started. Open up a new Flash document. First we are going to draw our mouse. You don't have to include anything specific in it, just make it look different from your normal mouse. It can also have a little animation in it, once you have converted it to a Movie Clip. So, select it and press F8 to convert it to a Movie Clip symbol. Call it "cursor".
Now let's add the code. Select the cursor, and press F9 to open up its action panel. Then type this:
onClipEvent (load) { Mouse.hide(); } onClipEvent (enterFrame) { this._x = _root._xmouse; this._y = _root._ymouse; }
That's it. Not much code, but let's explain what I have done.
onClipEvent (load) { Mouse.hide(); }
This calls upon the Mouse.hide() function when the Movie Clip loads. The Mouse.hide() function basically hides the mouse.
onClipEvent (enterFrame) { this._x = _root._xmouse; this._y = _root._ymouse; }
This code says that every time you enter the frame, then the Movie Clip's x position on the stage (this._x) will equal the x position of the mouse on the stage (_root._xmouse). You must always remember to put "_root." In front of main objects, as they are on the root timeline. Similarly so, the code also says that every time you enter the frame, the Movie Clip's y position on the stage (this._y) will equal the mouse's y position on the stage (_root._ymouse).
So that is all the code. Test your movie and see that it works. Great! We're done. But wait, hold on, it isn't dragging it around by the tip of the mouse? Ah! We forgot one small thing! To move the Movie Clip's registration point. If you double click on your Movie Clip, you should see a small cross in the middle of the screen. That is your Movie Clip's registration point. This is the point that your hidden cursor is dragging your custom cursor around by. Basically, it is what determines the exact x and y values of your Movie Clip. How can we fix this? Simple. Drag your cursor around until its tip is right on the registration point (give or take a few pixels). Now that is the point that it is dragged round by. Test your movie and you should see that it works. Well, thank you for reading this, and I hope you've learned something from it. Please join us for our next tutorial,
Leon.