Menu.menuHide

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

Usage 1:

var listenerObject:Object = new Object();
listenerObject.menuHide = function(eventObject:Object) {
    // Insert your code here.
};
menuInstance.addEventListener("menuHide", listenerObject);

Usage 2:

on (menuHide) {
    // Insert your code here.
}

Description

Event; broadcast to all registered listeners whenever a menu closes.

Components use a dispatcher-listener event model. When a Menu component dispatches a menuHide event, the event is handled by a function (also called a handler) that is attached to a listener object (listenerObject) that you create. You call the addEventListener() method and pass it the name of the handler and the name of the listener object as parameters.

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.menuHide event's event object has two additional properties:

For more information, see EventDispatcher class.

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. When the user clicks a second time, the menu is hidden and a listener for the menuHide event, menuListener, displays "Menu closed" 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("XXXXX");

// 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();
buttonListener.click = function(evt_obj:Object) {
 // get reference to the button
 var the_button:Button = evt_obj.target;
 // Display the menu at the bottom of the button.
 my_menu.show(the_button.x, the_button.y + the_button.height);
};
my_button.addEventListener("click", buttonListener);

// Create listener object.
var menuListener:Object = new Object();
menuListener.menuHide = function(evt_obj:Object) {
 trace("Menu closed.");
};

// Add listener.
my_menu.addEventListener("menuHide", menuListener);

See also

Menu.menuShow