Creating Custom Cursors

I l @ ve RuBoard

In Hour 7, "Moving and Changing Movie Clips," you learned how to set a movie clip's location to the location of the mouse with the _xmouse and _ymouse properties. While the movie clip remains at the location of the cursor, it is not useful as a cursor because the real cursor stays visible. We can change this, however, by getting rid of the cursor altogether with the Mouse.hide() function.

By first using Mouse.hide() and then making a movie clip follow the cursor location, you can effectively create a custom cursor.

This cursor can be anything you want: your own stylized arrow, a hand, or something that fits the movie you are working on.

Figure 13.1 shows an example of a movie clip that will be used as a cursor. It is just a simple arrow. Notice that the graphic is positioned so that the crosshairs that signify the center of the movie clip are at the tip of the arrow. When we set the location of the movie clip, this spot will be placed at the position we specify. This is often called the hotspot of the cursor.

Figure 13.1. An example of a cursor movie clip.

graphics/13fig01.jpg

If you want to switch from using a custom cursor back to the regular cursor, all you need to do is to use the Mouse.show() command to make the regular cursor visible again.

graphics/bulb.gif

How about an animated cursor? This is just as easy to create; you simply need to place the animation across multiple frames of the movie clip. No additional ActionScript is needed. Using an animated movie clip is just as easy as using a static one.


One last step in creating a custom cursor is to make sure that it appears on top of all the other movie clips. To switch the level of a movie clip, you can choose Modify, Arrange, Bring to Front. However, this only moves the movie clip above all other static movie clips on that layer. It does not move it above movie clips on other layers . Even if you placed the cursor movie clip in the top layer, it could still be behind movie clips created with ActionScript using the duplicateMovieClip and attachMovie commands.

To ensure that the movie clip is above all else, you will want to use the swapDepths command to bring the movie clip the very front.

The swapDepths command takes a movie clip and places it at a new level. A level can be any integer: 0, 1, 10, 9999, anything. If anything was at that level previously, it will now be at the former level of the other movie clip.

When you use the duplicateMovieClip or attachMovie commands, you specify a level for the new movie clip to reside. As long as these numbers are less than the level of the cursor movie clip, the cursor will always be on top. For instance, this command virtually ensures that the cursor movie clip stays on top:

 cursor.swapDepths(99999); 
I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net