Menu.hide()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

menuInstance.hide()

Returns

Nothing.

Description

Method; closes a menu.

Example

The following example creates a button and a two-item menu and displays the menu for an interval of 2000 milliseconds. When the interval expires, the closeMenu() function calls the menu.hide() method to close the menu. Clicking the Reset Menu button triggers the resetMenu() listener, which redisplays the menu and resets the interval.

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, {label:"Reset Menu", _x:100, _y:50});

// 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);

my_menu.show(100, 100);
// Call closeMenu after 2000 milliseconds.
var interval_id:Number = setInterval(closeMenu, 2000, my_menu);
function closeMenu(the_menu:Menu):Void {
    the_menu.hide();
    clearInterval(interval_id);
}
// Listener for button click; show menu and reset interval.
function resetMenu(evt_obj:Object):Void {
    clearInterval(interval_id);
    my_menu.show(100, 100);
    interval_id = setInterval(closeMenu, 2000, my_menu);
}
my_button.addEventListener("click", resetMenu);

See also

Menu.show()


Flash CS3