Required: Aspire UI Components Standard Edition
The uiMenu control creates a popup menu of individually selectable choices, similar to the File or Edit menu found in most software applications. The popup menu can have as many levels of submenus as needed.
Typically, you would not instantiate popup menus using this class directly; you would use the uiMenuBar control instead. There may be times however where it would be useful to create a popup menu using a specific context, eg. listening to a button click and using the uiMenu.popup() method to show a popup menu below the button.
import com.ghostwire.ui.controls.*; import com.ghostwire.ui.data.*; import com.ghostwire.ui.containers.*; import com.ghostwire.ui.enums.*; import com.ghostwire.ui.managers.*; import com.ghostwire.ui.events.*; var btn:uiLabelButton = new uiLabelButton("Help"); btn.addEventListener(MouseEvent.CLICK,on_btnClick); addChild(btn); var feedbackText:uiText = new uiText(); feedbackText.move(0,30); addChild(feedbackText); var popMenuXML:XML = <menu> <item label="ItemA" /> <item label="ItemB" enabled="false" /> <item label="ItemC" > <!-- a group of radio items --> <item label="ItemCSubMenuItemA" group="RadioGroup1" /> <item label="ItemCSubMenuItemB" group="RadioGroup1" /> <item label="ItemCSubMenuItemC" group="RadioGroup1" checked="true" /> </item> <!-- an empty item denotes a separator --> <item /> <!-- a check item --> <item label="ItemD" checked="true" /> <item /> <item label="ItemE" checked="false" /> </menu> var popMenuModel:uiModel = new uiModel(popMenuXML); function on_btnClick(evt:Event):void { var menu:uiMenu = uiMenu.popup(popMenuModel,btn); menu.addEventListener(uiMenuEvent.MENU_SELECT,on_menuSelect,false,0,true); } function on_menuSelect(evt:uiMenuEvent):void { feedbackText.text = "Label: "+evt.item.label+" has been selected"; feedbackText.text += "\ngroup property value: "+evt.item.group; feedbackText.text += "\nchecked property value: "+evt.item.checked; }
Each menu item can specify several attributes that determine how the item is displayed and behave. The following table lists the attributes you can specify:
| Attribute | Type | Description |
|---|---|---|
| checked | Boolean | Applicable only for check and radio items. Specifies whether a check or radio item is selected. If the checked property is defined, but the group property is undefined, the item is treated as a check item. |
| enabled | Boolean | Specifies whether the user can select the menu item (true), or not (false). If not specified, a default value of true is used. |
| group | String | If defined, the item is treated as a radio item. If undefined, the item is a normal menu item. |
| icon | String | Specifies the source of an image asset to display in the menu item (will be displayed to the left of the text label). This property is ignored for check and radio items. |
| id | String | Optional. If defined, the data object can be accessed via the getItemById() method of the model. This property should be unique (no two item should use the same identifier). This is useful in case you need to access deeply nested items in your application code. |
| label | String | Specifies the text to display in the menu item. |
Notice that a type attribute is absent and unnecessary since the following rules apply:
Where an item has child nodes (submenu items), the data object created from the parsing of the XML will also contain a child property indicating an Array of the child menu items. An item with submenu items is non-selectable (clicking on it does not dispatch a uiMenuEvent.SELECT event).
When a uiMenu control is shown, the user can use the following keys to interact with the control:
| Key | Action |
|---|---|
| Down Arrow | Highlights the next item on the list. |
| Escape | Closes the menu. |
| Left Arrow | If currently on a submenu, closes the submenu and move up to parent item. |
| Right Arrow | Opens submenu if the currently highlighted item has one. |
| Spacebar | Selects the currently highlighted item if it is not disabled. |
| Tab | Closes the menu. |
| Up Arrow | Highlights the previous item on the list. |
For more information on the members of the com.ghostwire.ui.controls.uiMenu class, please refer to the API Reference.