Button.trackAsMenu Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Button.trackAsMenu Property Flash 6

modifies the button's onRelease( ) handler requirements, enabling menu-style behaviorFlash 3; property form introduced in read/write
theButton.trackAsMenu

Description

The Boolean trackAsMenu property modifies the conditions that cause theButton's onRelease( ) event handler to execute. It is normally used to turn a group of buttons into a menu. When trackAsMenu is undefined (the default) or false, a button's onRelease( ) handler will execute only when the mouse is both pressed and released over the button. When trackAsMenu is true, releasing the mouse over the button will always trigger its onRelease( ) handler, unless the mouse was originally pressed over a button for which trackAsMenu is false or undefined. The following scenarios demonstrate the result of this subtle change in behavior.

Consider a "Products" menu button with three suboption buttons: Music, Books, and Software. These steps show how the menu works when trackAsMenu is false for all four buttons:

  1. Products button is pressed.

  2. Suboption buttons appear (are attached at runtime).

  3. Mouse moves over first option, Music. The Music button's Up state is shown.

  4. Mouse is released over Music. No onRelease( ) handler is executed, because the mouse was pressed over Products but released over a different button, Music. User's selection is not activated.

These steps show how the menu works when trackAsMenu is true for all four buttons:

  1. Products button is pressed.

  2. Suboption buttons appear (are attached at runtime).

  3. Mouse moves over first option, Music. The Music button's Down state is shown, revealing the user's current selection.

  4. Mouse is released over Music. The Music button's onRelease( ) handler is executed. The user's selection is activated.

Notice that as a side effect of trackAsMenu being true, the Down state of a button is always shown when the mouse pointer is over the button and the mouse button is down (even if the mouse was originally pressed on another button). The button's onRollOver( ) and onRollOut( ) handlers, however, are not triggered unless the mouse button is up.

The trackAsMenu property should be set the same for all buttons in a menu or other group-based interface; otherwise, mayhem and confusion can ensue.

Example

On frame 1 of a movie, create three button instances, named b1, b2, and b3, each with unique Up, Over, and Down states. Then attach the following code to frame 1 and choose Control figs/u2192.gif Test Movie. Click the mouse over b1 and release it over b2. Notice that b2's Down state is displayed, and its onRelease( ) handler executes.

b1.trackAsMenu = true; b2.trackAsMenu = true; b3.trackAsMenu = true;     b1.onRelease = b2.onRelease = b3.onRelease = release;     function release () {   trace(this._name + " released"); }

See Also

Button.onRelease, Button.onRollOver, Button.onRollOut



    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