Menu.setMenuItemSelected()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

menuInstance.setMenuItemSelected(item, select)

Parameters

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

select A Boolean value indicating whether the item is selected (true) or not (false). If the item is a check box, its check mark is visible or not visible. If a selected item is a radio button, it becomes the current selection in the radio group.

Returns

Nothing.

Description

Method; changes the selected attribute of the item to the state specified by the select parameter. If this call results in a change of state, the item is redrawn with the new state. This is only meaningful for items whose type attribute is set to "radio" or "check", because it causes their dot or check to appear or disappear. If you call this method on an item whose type is "normal" or "separator", it has no effect.

Example

The following example creates a menu with two menu items, the second of which is a check box menu item. The example calls the setMenuItemSelected() method to put the check box menu item in a selected state.

You first 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({type:"check", label:"2nd Item"})

// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);

var myItem = my_menu.getMenuItemAt(1);
my_menu.setMenuItemSelected(myItem, true);

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