Mouse Object

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Mouse Object Flash 5; enhanced in Flash 6 to add listener events

mouse events and control over mouse pointer visibility
Mouse.methodName()

Methods

addListener( )

Registers an object to receive onMouseDown( ), onMouseMove( ), and onMouseUp( ) events.

hide( )

Hides the mouse pointer.

removeListener( )

Cancels event notices for the specified listener.

show( )

Enables the mouse pointer.

Listener events

onMouseDown( )

Occurs when the primary mouse button is depressed.

onMouseMove( )

Occurs when the mouse pointer moves.

onMouseUp( )

Occurs when the primary mouse button is released.

Description

The Mouse object provides feedback from mouse events and control over the visibility of the mouse pointer. Using the Mouse events, we can create mouse-driven interfaces that respond to mouseclicks and mouse movement. However, for menu- and button-based applications, the mouse-related Button events (onPress( ), onRelease( ), onRollOver( ), etc.) provide easier access to mouse actions. The mouse event handlers, such as onMouseDown( ), are useful when you want to trap mouseclicks not associated with a particular button. For example, you can use them to trap a mouseclick anywhere on-screen, which might be useful to advance a slideshow.

We use Mouse.hide( ) to conceal the system mouse pointer, usually in order to replace it with a customized mouse pointer, as shown in the Example under Mouse.hide( ). It may also be desirable to hide the mouse pointer in fullscreen, keyboard-controlled movies or for touch-screen kiosks.

Note that the Mouse object does not tell us the location of the mouse pointer. Use _root._xmouse and _root._ymouse to determine the mouse pointer's location relative to the main Stage. Use the _xmouse and _ymouse properties of a movie clip object to determine the mouse pointer's location relative to the clip.

Usage

The onMouseDown( ), onMouseMove( ) and onMouseUp( ) listener events were added to the Mouse object in Flash 6. They are generally preferred over the analogous Flash 5-style clip events mouseDown, mouseMove, and mouseUp, which are used within an onClipEvent block to detect mouse input. However, in Flash 6, the updateAfterEvent( ) function, which refreshes the screen between frames, can be used only with MovieClip mouse or key events or with setInterval( ). Hence, when a screen refresh is required between frames, the MovieClip.onMouseDown( ), MovieClip.onMouseMove( ), and MovieClip.onMouseUp( ) handlers must be used. See those entries in this Language Reference for details. Future versions of the Player will likely include support for updateAfterEvent( ) from Mouse listener events.

See Also

Button.onPress( ), Button.onRelease( ), MovieClip.onMouseDown( ), MovieClip.onMouseMove( ), MovieClip.onMouseUp( ), MovieClip._xmouse, MovieClip._ymouse, updateAfterEvent( )



    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