Replacing The Mouse Pointer
To make the interface more usable, you might want to change the mouse pointer (or cursor) when a user moves the pointer over a draggable instance. This helps users easily recognize the items that can or cannot be moved around on the Stage.When you create a custom pointer, you might want to use that pointer for the entire duration of the SWF file. If so, you'll use code like the following:
This ActionScript takes a movie clip on the Stage with the instance name customPointer_mc and uses that movie clip as a custom mouse pointer. First, you hide the default system pointer (an arrow) using Mouse.hide() and then you define a onMouseMove event handler, which calls every time you move the mouse around the Stage.In the next exercise you will add ActionScript that's similar to the previous snippet to change the mouse pointer when it hovers over and drags the three movie clip shapes in the SWF file.
Mouse.hide();
customPointer_mc.onMouseMove = function() {
customPointer_mc._x = _xmouse;
customPointer_mc._y = _ymouse;
updateAfterEvent();
};
Exercise 4: Creating your own mouse pointer
When you add custom mouse pointers in certain areas, you can greatly increase the usability of your SWF files. By default, Flash changes the pointer for buttons (or movie clips, which behave like buttons) to a hand icon to indicate that the particular instance is clickable. Without the hand icon, the user might never know what they can or cannot click. Nothing can frustrate users more than a SWF file that they have no idea how to navigate.In this exercise, you add code to modify the mouse pointer when it moves over draggable instances on the Stage. This notifies users that they can drag certain movie clips.
1. You need to add or create a custom pointer in the Library. Select Insert > New Symbol to create a new symbol. Name it pointer, and select Movie Clip as the symbol's behavior. Click OK to enter symbol-editing mode, in which you can draw a graphic for the mouse pointer. Make sure that it's somewhat small (5 to 20 pixels in height and width), similar to the following figure.
Figure 6.17. Your custom pointer should be between 5 and 20 pixels in width and height.

Figure 6.18. Create a custom pointer in the Library.

function showPointer() {
Mouse.hide();
pointer_mc._visible = true;
pointer_mc.onMouseMove = function() {
pointer_mc._x = _xmouse;
pointer_mc._y = _ymouse;
updateAfterEvent();
};
}
function hidePointer() {
pointer_mc._visible = false;
Mouse.show();
delete pointer_mc.onMouseMove;
}

Unlike the event handlers you used earlier, this code doesn't define its event handlers with an inline function. Instead, it uses the functions you defined in step 3. Because of this, you assign the function name as the event handler. It is important to make sure that you don't add parentheses after the function name, or else you'll experience unexpected results.5. Repeat step 4 by duplicating the code snippet in step 4 for both the square_mc and TRiangle_mc instances. Add the following ActionScript after the code you added in step 4.
circle_mc.onRollOver = showPointer;
circle_mc.onRollOut = hidePointer;
6. Make sure that the custom pointer instance on the Stage is not visible by default. To accomplish this, you need to set the _visibility property for the pointer to false by default, as shown in the following code:
square_mc.onRollOver = showPointer;
square_mc.onRollOut = hidePointer;
triangle_mc.onRollOver = showPointer;
triangle_mc.onRollOut = hidePointer;
pointer_mc._visible = false;
In this exercise, you added functions to your code that change the default mouse pointer to a custom one when the pointer hovers over each shape. This increases the usability of the project. In the next exercise, you modify the mouse pointer to have multiple states, which means it will look different depending on how the user interacts with the shapes. Save (File > Save) the changes you made to the document.
Exercise 5: Creating multiple movie clip states
If you want to make the game a bit more interactive, you can create multiple "states" for each of the shapes in your SWF file. For example, you could show different images for an object on the Stage when the mouse pointer hovers or drags over them, or after you drop a shape in a hole.
1. Double-click circle_mc on the Stage or in the Library to open the instance in symbol-editing mode.2. Double-click Layer 1 on the Timeline in symbol editing mode. Rename the layer shape and then click Insert Layer two times. Rename the two new layers actions and labels.3. Select frame 6 in the actions layer and press F6 to create a key frame. Then select frame 6 on the labels layer's Timeline and press F6 to create another keyframe.4. Select frame 10 of the actions layer and the labels layer. Press the Ctrl (Windows) or Command key and click each frame to select them at the same time. Then press the F5 to extend the frames on each layer to frame 10.5. Add the following ActionScript to both frames 1 and 6 in the actions layer (as you can see in Figure 6.19).
stop();
Figure 6.19. Add frame labels to the Timeline. This figure shows the symbol's background layer.

Then, select frame 6 of the labels layer and assign the frame label on. This frame contains the pointer graphic when you placed over the hole and successfully hit tests. When you're finished, the Timeline should look similar to the following figure.
7. Select frame 6 of the shape layer and press F6 to insert a keyframe and modify the shape for the on state. For example, you might want to change the color of the graphic (Figure 6.20).
Figure 6.20. Change the shape, pattern, or color of the graphic on frame 6. In this example, there is no "depth" to the shape on frame 6, which makes the instance appear as if it has been placed in the corresponding "hole."

10. Repeat step 9, adding the equivalent ActionScript for the square_mc and TRiangle_mc movie clip instances as well. Remember to check the final FLA file (06/complete /shapegame.FLA) for guidance if necessary.11. Because the movie clip states change when they collide with their matching "hole" movie clips, you need to reset the playhead to the default states when the user clicks the reset button. To return the shapes back to their original states, you need to modify the onRelease event handler for the reset_btn Button instance to what's shown in the following code. The new ActionScript is in boldface.
circle_mc.onRelease = function() {
circle_mc.stopDrag();
if (circle_mc.hitTest(circleHole_mc)) {
circle_mc._x = circleHole_mc._x;
circle_mc._y = circleHole_mc._y;
checkShapes();
circle_mc.gotoAndStop("on");
}
};
reset_btn.onRelease = function() {
circle_mc._x = circleInitX;
circle_mc._y = circleInitY;
square_mc._x = squareInitX;
square_mc._y = squareInitY;
triangle_mc._x = triangleInitX;
triangle_mc._y = triangleInitY;
circle_mc.gotoAndStop("off");
square_mc.gotoAndStop("off");
triangle_mc.gotoAndStop("off");
}
You add the three new lines of code (the lines in boldface), which you use to reset the playhead back to the off frame label when the user completes the game. This makes each shape return to its original position, and appearance. Now you have added all of the code necessary to make this file work, and all that remains is to see that it functions correctly when running in Flash Player.Test the SWF file in either the Flash environment (Control > Test Movie) or an external browser (F12). When you test the SWF file, you can drag the three shapes around the Stage. You drag a shape over a corresponding hole and release the mouse button; the shape changes to its second state.When all the shapes are in the proper holes, you then see your movie clip message display on the Stage. When you click the reset_btn Button instance, it returns each of the shapes to its original coordinates and its original state.Make sure that you save the changes that you made to the file if you are happy with the results.