One of the most common modifications designers make to a Flash interface is the addition of a custom cursor. After spending weeks, months (years?) building a really cool interactive with custom buttons, menus, and all kinds of eye candy, do we really want people to mouse around with that silly black arrow? Better to give them a cursor that fits the style of our labor of love.
So in this exercise we'll build a simple custom cursor that changes appearance when it scrolls over a button.
For now, use this Flash file; in it I already have a cursor drawn for you. You can make your own later.
onClipEvent (load) {
Mouse.hide();
this.swapDepths(99999);
}
onClipEvent (enterFrame) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
onClipEvent (unload) {
Mouse.show;
}
The first bit of code hides the "real" cursor. We've also added a swapDepths command. This line moves the cursor (this) to the 99,999th level of the stage. Since it's unlikely that there will be 100,000 objects on stage at any one time, we can be fairly confident that the cursor movie clip will be on top of everything. This is important, because a cursor that disappears behind an object is not very useful.
The second piece of code causes the cursor movie clip to follow the mouse. Unlike onClipEvent (load) which happens only once, onClipEvent (enterFrame) happens continuously while the movie is playing.
The third handler is not always necessary. If you plan on using the same cursor for your entire movie, you don't need it. However, if you plan on going back to the regular cursor at some point, you'll have to turn it back on. This code causes the regular cursor reappear once you've left the frame that has the custom cursor movie clip.
on (rollOver) {
cursor_in.gotoAndStop(2);
}
on (rollOut) {
cursor_in.gotoAndStop(1);
}
This code actually uses the button to control the cursor movie clip, very much like the movie clip exercise we did a couple weeks ago. In this case, rather than a press or release handler, we're using a rollOver and rollOut. When the cursor rolls over the button, the playhead inside the cursor movie clip jumps to (and stops on) frame 2, which as you should recall, is the yellow arrow. When the cursor rolls off of the button, the cursor timeline goes back to frame 1 (the purple arrow). The effect is a cursor that changes color when it hits the button.
Some possibilities: