Menu.setMenuItemEnabled()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

menuInstance.setMenuItemEnabled(item, enable)

Parameters

item An XML node; the target menu item's node in the data provider.

enable A Boolean value indicating whether the item is enabled (true) or not (false).

Returns

Nothing.

Description

Method; changes the target item's enabled attribute to the state specified in the enable parameter. If this call results in a change of state, the item is redrawn with the new state.

Example

The following example creates a menu with two menu items and calls the setMenuItemEnabled() method to disable the first one.

First, you drag a Menu component to the library and then add the following code to Frame 1:

/**
 Requires:
  - Menu component in library
*/

import mx.controls.Menu;

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

// Select the first menu item and disable it.
var item_obj:Object = my_menu.getMenuItemAt(0);
my_menu.setMenuItemEnabled(item_obj, false);

// Show and position the menu.
my_menu.show(100, 20);

See also

Menu.setMenuItemSelected()