User Guide

Menu.setMenuItemSelected() 931
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);