Check box menu items

A menu item whose type attribute is set to check acts as check box item in the menu; when the selected attribute is set to true, a check mark appears beside the menu item's label. When a check box item is selected, its state automatically toggles, and a change event is broadcast to all listeners on the root menu. However, although a check box menu item behaves similarly to a CheckBox component, a check box menu item appears visually without the box surrounding the check. So an unselected check box menu item looks like a normal menu item until selected.

The following example defines three check box menu items:

<menu>
    <menuitem label="Apples" type="check" instanceName="buyApples" selected="true" />
    <menuitem label="Oranges" type="check" instanceName="buyOranges" selected="false" />
    <menuitem label="Bananas" type="check" instanceName="buyBananas" selected="false" />
</menu> 

You can use the instance names in ActionScript to access the menu items directly from the menu itself, as in the following example:

myMenu.setMenuItemSelected(myMenu.buyapples, true);
myMenu.setMenuItemSelected(myMenu.buyoranges, false);

NOTE

The selected attribute should be modified only with the setMenuItemSelected() method. You can directly examine the selected attribute, but it returns a string value of true or false.