Mouse.onMouseDown( ) Listener Event

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Mouse.onMouseDown( ) Listener Event Flash 6

occurs when the primary mouse button is depressed
listener.onMouseDown()

Description

Like the Button.onPress( ) event, the onMouseDown( ) event detects the downstroke of a mouseclick. Unlike the button press event, onMouseDown( ) is not tied to the hit area of a button object (a button's hit area is defined graphically when you create the button in the Flash authoring tool, whereas a movie clip's hit area can also be set via the hitArea property). The onMouseDown( ) event occurs each time the primary mouse button is depressed while the mouse pointer is over any part of the Stage.

To respond to an onMouseDown( ) event, we must assign a callback function to the onMouseDown property of some object, such as listener, and then add listener as a listener using Mouse.addListener( ), as follows:

// Create a generic object (although it can be any type of object) mouseListener = new Object();     // First assign a callback function to the object's onMouseDown property mouseListener.onMouseDown = function () {   trace("The mouse was pressed!"); }     // Then register the listener with the Mouse object Mouse.addListener(mouseListener);

Any number of listener objects of any class can respond to the onMouseDown( ) event.

The onMouseDown( ) event executes immediately when the mouse is pressed, independently of the code on a movie's timeline(s). However, visual changes to the movie made by the listener are not rendered until the next frame refresh, which is determined by the frame rate of the movie. Unfortunately, in Flash 6, updateAfterEvent( ) cannot be used to force a screen refresh from within an onMouseDown( ) listener; updateAfterEvent( ) has an effect only when invoked either from a movie clip mouse or key event or a setInterval( ) callback. For example:

someMovieClip_mc.onMouseDown = function () {   // Scale the clip to 200% of its original size.   this._xscale = this._yscale = 200;   // Refresh the screen. In Flash 6, this does not work in a mouse listener.   updateAfterEvent(); }

See Also

Button.onPress( ), Mouse.addListener( ), Mouse.onMouseMove( ), Mouse.onMouseUp( ), MovieClip.onMouseDown( )



    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