Aspire UI Components (Flash ActionScript 3.0) Docs

uiMenu

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.


Using uiMenu

ActionScript 3.0 Example

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;
 
}

uiMenu Example

Using the “classic” skin:
uiMenu classic skin Example


Menu Items

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:

AttributeTypeDescription
checkedBooleanApplicable 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.
enabledBooleanSpecifies whether the user can select the menu item (true), or not (false). If not specified, a default value of true is used.
groupStringIf defined, the item is treated as a radio item. If undefined, the item is a normal menu item.
iconStringSpecifies 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.
idStringOptional. 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.
labelStringSpecifies the text to display in the menu item.

Notice that a type attribute is absent and unnecessary since the following rules apply:

  • all menu items are created as normal menu items by default;
  • if an item has the checked property defined, it is created as a check item;
  • if an item has the group property defined, it is created as a radio item;
  • if an item is empty or does not define the label property, it is created as a separator.

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).


User Interaction

When a uiMenu control is shown, the user can use the following keys to interact with the control:

KeyAction
Down ArrowHighlights the next item on the list.
EscapeCloses the menu.
Left ArrowIf currently on a submenu, closes the submenu and move up to parent item.
Right ArrowOpens submenu if the currently highlighted item has one.
SpacebarSelects the currently highlighted item if it is not disabled.
TabCloses the menu.
Up ArrowHighlights the previous item on the list.


See Also

API Reference

For more information on the members of the com.ghostwire.ui.controls.uiMenu class, please refer to the API Reference.


 
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki