Button.trackAsMenu Property | Flash 6 |
modifies the button's onRelease( ) handler requirements, enabling menu-style behaviorFlash 3; property form introduced in | read/write |
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:
Products button is pressed.
Suboption buttons appear (are attached at runtime).
Mouse moves over first option, Music. The Music button's Up state is shown.
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:
Products button is pressed.
Suboption buttons appear (are attached at runtime).
Mouse moves over first option, Music. The Music button's Down state is shown, revealing the user's current selection.
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.
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 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"); }
Button.onRelease, Button.onRollOver, Button.onRollOut