User Guide
920 Menu component (Flash Professional only)
When the event is triggered, it automatically passes an event object (eventObject) to the
handler. Each event object has properties that contain information about the event. You can
use these properties to write code that handles the event. The
Menu.menuShow event’s event
object has two additional properties:
■ menuBar A reference to the MenuBar instance that is the parent of the target menu.
When the target menu does not belong to a MenuBar instance, this value is
undefined.
■ menu A reference to the Menu instance that is shown.
For more information, see “EventDispatcher class” on page 499.
Example
The following example creates a button and a two-item menu. When the user clicks the
button, a listener for a button click event displays the menu. A listener for the
menuShow
event,
menuListener, displays “Menu open” in the Output panel.
You first drag a Menu component and a Button component to the library and then add the
following code to Frame 1:
/**
Requires:
- Menu component in library
- Button component in library
*/
import mx.controls.Button;
import mx.controls.Menu;
this.createClassObject(Button, "my_button", 10);
// Create an XML object to act as a factory.
var my_xml:XML = new XML();
// The item created next does not appear in the menu.
// The createMenu() method call (below) expects to
// receive a root element whose children will become
// the items. This is just a simple way to create that
// root element and give it a convenient name.
var menuDP_obj:Object = my_xml.addMenuItem("Edit");
// Add the menu items.
menuDP_obj.addMenuItem({label:"1st Item"});
menuDP_obj.addMenuItem({label:"2nd Item"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
// Add a button that displays the menu when the button is clicked.
var buttonListener:Object = new Object();