Mouse.hide( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Mouse.hide( ) Method Flash 5

make the mouse pointer disappear
Mouse.hide()

Returns

Either 1 or 0, indicating whether the mouse was shown (1) or hidden (0) before the call to hide( ).

Description

The hide( ) method causes the normal mouse pointer (usually an arrow, although sometimes a hand) to disappear when the mouse is over any part of the Flash Player. The normal system pointer reappears when the mouse passes outside the Flash Player's active Stage area.

Usage

Note that even after Mouse.hide( ) has been invoked, the normal system text I-beam cursor appears when the mouse hovers over an editable text field.

Example

The hide( ) method is used to conceal the default system mouse pointer, typically in order to replace it with a custom pointer. In Flash, a custom pointer is nothing more than a movie clip that follows the mouse. Using the MovieClip.onMouseMove( ) event handler, we can cause a movie clip to follow the mouse by updating the clip's _x and _y properties when the mouse moves. The following code demonstrates the technique:

Mouse.hide();     // Makes the customPointer_mc movie clip follow the mouse. // Note that customPointer_mc must be on the main timeline for this // example to work. To place customPointer_mc on another timeline, we'd // have to use globalToLocal() to convert from main timeline coordinates // to the local customPointer_mc coordinate space. customPointer_mc.onMouseMove = function () {   this._x = _root._xmouse;   this._y = _root._ymouse;   // Refresh screen immediately, without waiting for the next frame.   updateAfterEvent(); }

This code does not use a Mouse.onMouseMove( ) listener, because in Flash 6 updateAfterEvent( ) works only with a MovieClip mouse or key event or with setInterval( ).

It may also be desirable to hide the custom pointer when the mouse is inactive, say, because the pointer has left the Flash Player's active Stage area, in which case the system pointer appears, and there are two pointers on screen (the custom pointer and the system pointer). The following example shows how to adapt the preceding code to hide the cursor after 5 seconds of inactivity:

Mouse.hide();     // Makes the customPointer_mc movie clip follow the mouse. customPointer_mc.onMouseMove = function () {   this._x = _root._xmouse;   this._y = _root._ymouse;   this.lastMove = getTimer();   // Refresh screen immediately, without waiting for the next frame.   updateAfterEvent(); }     customPointer_mc.onEnterFrame = function () {   if (getTimer() - this.lastMove > 5000) {     this._visible = false;   } else {     this._visible = true;   } }

To change a custom pointer to a custom hand pointer when the mouse hovers over a button, use that button's rollOver event to set the custom pointer clip to a frame containing the custom hand, and use the rollOut event to set the custom pointer back to the default, as follows:

go_btn.onRollOver = function () {   _root.customPointer_mc.gotoAndStop("hand"); }     go_btn.onRollOut = function () {   _root.customPointer_mc.gotoAndStop("default"); }

In all cases, remember to place the custom pointer on the top layer of your movie so that it appears above all other content. Alternatively, use duplicateMovieClip( ) or attachMovie( ) to generate the custom pointer clip dynamically and assign it a very high depth.

See Also

Mouse.show( ), MovieClip._xmouse, MovieClip._ymouse



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

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