Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Creating Interaction with ActionScript > Creating interactivity and visual effects > Creating a custom mouse pointer | |||
A standard mouse pointer is the operating system's on-screen representation of the position of the user's mouse. By replacing the standard pointer with one you design in Flash, you can integrate the user's mouse movement within the SWF file more closely. The sample in this section uses a custom pointer that looks like a large arrow. The power of this feature, however, is your ability to make the custom pointer look like anything--for example, a football to be carried to the goal line or a swatch of fabric pulled over a chair to change its color.
To create a custom pointer, you design the pointer movie clip on the Stage. Then, in ActionScript, you hide the standard pointer and track its movement. To hide the standard pointer, you use the hide() method of the built-in Mouse class (see hide (Mouse.hide method) in the ActionScript 2.0 Language Reference). To see an animated demonstration of a custom pointer, move your pointer over the following SWF file.
To create a custom pointer:
Mouse.hide();
cursor_mc.onMouseMove = function() {
this._x = _xmouse;
this._y = _ymouse;
updateAfterEvent();
};
The Mouse.hide() method hides the pointer when the movie clip first appears on the Stage; the onMouseMove function positions the custom pointer at the same place as the pointer and calls updateAfterEvent() whenever the user moves the mouse.
The updateAfterEvent() function immediately refreshes the screen after the specified event occurs, rather than when the next frame is drawn, which is the default behavior. (See updateAfterEvent function in the ActionScript 2.0 Language Reference.)
Buttons still function when you use a custom mouse pointer. It's a good idea to put the custom pointer on the top layer of the timeline so that, as you move the mouse in the SWF file, the custom pointer appears in front of buttons and other objects in other layers. Also, the tip of a custom pointer is the registration point of the movie clip you're using as the custom pointer. Therefore, if you want a certain part of the movie clip to act as the tip of the pointer, set the registration point coordinates of the clip to be that point.
For more information about the methods of the Mouse class, see Mouse in the ActionScript 2.0 Language Reference.
|
|
|
|