View comments | RSS feed
Methods | Properties | Effects | Events | Styles | Examples Frames | No Frames

mx.controls
Class Menu

Inheritance ImageInheritance ImageInheritance ImageInheritance ImageInheritance Image


class Menu
extends mx.controls.listclasses.ScrollSelectList

The Menu control creates a pop-up menu of individually selectable choices, similar to the File or Edit menu found in most software applications. After a Menu opens, it remains visible until it is closed by any of the following:

The Menu class has no corresponding MXML tag. It must be created via script.

Click here to view the Examples

See Also
    treeclasses.TreeDataProvider
    treeclasses.XMLTreeDataProvider
    mx.managers.PopUpManager
    mx.effects.Tween



Constructors
Menu ( )
Constructor



Methods
       addMenuItem( arg: Object) :  Object
Appends a menu item to the end of this menu.
       addMenuItemAt( index: Number, arg: Object) :  Object
Inserts an item into this menu at a specified location.
staticcreateMenu( parent, mdp, initObj)
Returns the Menu instance described by the given MenuDataProvider, and places the instance in the given parent container.
       getMenuItemAt( index: Number) :  Object
Get a reference to an item from this menu.
       getRootMenu( ) :  mx.controls.Menu
From any menu, walks up the parent menu chain and finds the root menu.
       hide( ) :  Void
If the Menu is visible, hide it and any visible submenus.
       indexOf( item: Object) :  Number
Returns the index of an item in this menu.
staticisItemEnabled( itm: Object) :  Boolean
If true, item is enabled.
staticisItemSelected( itm: Object) :  Boolean
If true, item is selected.
       measure( ) :  Void
Measures the menu items to calculate its height and width.
       removeAll( ) :  Object
Removes all items from the menu.
       removeMenuItem( item: Object) :  Object
Removes an item from the menu.
       removeMenuItemAt( index: Number) :  Object
Removes the item at a given location from the menu.
       setMenuItemEnabled( item: Object, enable: Boolean) :  Void
Marks a menu item as enabled (or not).
       setMenuItemSelected( item: Object, select: Boolean) :  Void
Marks an item as selected (or not).
       show( x: Number, y: Number) :  Void
If the Menu isn't visible, place the top left corner at the given coordinates, resize the menu as needed, and make it visible.

Methods inherited from class mx.controls.listclasses.ScrollSelectList
addItem   addItemAt   calculateWidths   clearSelected   createChildren   draw   fillRowsFromBottom   fillRowsFromTop   getDropLocation   getItemAt   hideDropFeedback   isSelected   layoutChildren   measure   removeAll   removeItemAt   replaceItemAt   setPropertiesAt   showDropFeedback   sortItems   sortItemsBy  

Methods inherited from class mx.core.ScrollView
childLoaded   createChildren   createChildWithStyles   getViewMetrics   init   layoutChildren   setScrollProperties  

Methods inherited from class mx.core.View
childLoaded   constructObject2   createChild   createChildren   destroyAllChildren   destroyChild   destroyChildAt   draw   getBorderMetrics   getChildAt   getChildIndex   getViewMetrics   init   layoutChildren   layoutChrome   setChildIndex  

Methods inherited from class mx.core.UIComponent
drawFocus   getFocus   getFocusManager   setEnabled   setFocus  

Methods inherited from class mx.core.UIObject
addEventListener   applyProperties   buildDepthTable   commitProperties   constructObject2   createAccessibilityImplementation   createChildAtDepth   createChildren   createClassChildAtDepth   createClassObject   createEmptyObject   destroyObject   dispatchEvent   doLater   draw   drawRect   executeBindings   fillRect   findNextAvailableDepth   getRepeaterItem   getStyle   handleEvent   init   invalidate   invalidateLayout   invalidateProperties   invalidateSize   invalidateStyle   layoutChildren   measure   move   redraw   removeEventListener   setDepthAbove   setDepthBelow   setMask   setSize   setSizeNoLayout   setStyle   swapDepths  



Properties
staticversion: String
Version string for this class.

Properties inherited from class mx.controls.listclasses.ScrollSelectList
cellRenderer   dataProvider   dataTipField   dataTipFunction   dragEnabled   dropIndicatorSkin   iconField   iconFunction   labelField   labelFunction   multipleSelection   rowCount   rowHeight   rowRenderer   selectable   selectedIndex   selectedIndices   selectedItem   selectedItems   showDataTips   value   variableRowHeight   verticalAlign   wordWrap  

Properties inherited from class mx.core.ScrollView
className   hPosition   hScrollPolicy   liveScrolling   maxHPosition   maxVPosition   scrollTipFunction   showScrollTips   version   vPosition   vScrollPolicy  

Properties inherited from class mx.core.View
baselinePosition   className   numChildren   version  

Properties inherited from class mx.core.UIComponent
enabled   errorString   tabEnabled   tabIndex   version  

Properties inherited from class mx.core.UIObject
alpha   baselinePosition   className   depth   documentDescriptor   height   heightFlex   id   instanceIndices   isDocument   kStretch   layoutHeight   layoutWidth   maxHeight   maxWidth   minHeight   minWidth   mouseX   mouseY   nestLevel   oldHeight   oldWidth   oldX   oldY   parent   parentApplication   parentDocument   percentHeight   percentWidth   preferredHeight   preferredWidth   repeaterIndices   scaleX   scaleY   styleName   tabEnabled   toolTip   version   visible   width   widthFlex   x   y  



Effects

Effects inherited from class mx.core.UIComponent
focusInEffect   focusOutEffect  

Effects inherited from class mx.core.UIObject
creationCompleteEffect   hideEffect   mouseDownEffect   mouseOutEffect   mouseOverEffect   mouseUpEffect   moveEffect   resizeEffect   showEffect  



Events
changeBroadcast when a user selects an item in the Menu control. The event object contains the properties:
- menuBar MenuBar instance that is the parent of the selected Menu control, or undefined when the target Menu control does not belong to a MenuBar control.
- menu Menu instance that was hidden, of type Menu.
- menuItem Selected menu item. Access the menu item properties as:
eventobj.menuItem.attributes.attribName 

- groupName Name of the radio-group to which the item belongs. Undefined when the target item is not in a radio group. The data type is String.
- target Reference to the component that triggered the event.
- type The name of the event, change.
menuHideBroadcast when a menu or submenu closes. The event object contains the properties:
- menuBar MenuBar instance that is the parent of the selected Menu control, or undefined when the target Menu control does not belong to a MenuBar control.
- menuItem Selected menu item. Access the menu item properties as:
eventobj.menuItem.attributes.attribName 

- target Reference to the component that triggered the event.
- type The name of the event, menuHide.
menuShowBroadcast when the entire menu or a submenu opens. The event object contains the properties:
- menuBar MenuBar instance that is the parent of the selected Menu control, or undefined when the target Menu control does not belong to a MenuBar control.
- menu Menu instance, of type Menu.
- menuItem Selected menu item. Access the menu item properties as:
eventobj.menuItem.attributes.attribName 

- target Reference to the component that triggered the event.
- type The name of the event, menuShow.
rollOutBroadcast when the cursor rolls off of a Menu item. The event object contains the properties:
- menuItem Selected menu item. Access the menu item properties as:
eventobj.menuItem.attributes.attribName 

- menu Menu instance, of type Menu.
- menuBar MenuBar instance that is the parent of the selected Menu control, or undefined when the target Menu control does not belong to a MenuBar control.
- target Reference to the component that triggered the event.
- type The name of the event, rollOut.
rollOverBroadcast when the cursor rolls over a Menu item. The event object contains the properties:
- menuItem Selected menu item. Access the menu item properties as:
eventobj.menuItem.attributes.attribName

- menu Menu instance, of type Menu.
- menuBar MenuBar instance that is the parent of the selected Menu control, or undefined when the target Menu control does not belong to a MenuBar control.
- target Reference to the component that triggered the event.
- type The name of the event, rollOver.

Events inherited from class: mx.controls.listclasses.ScrollSelectList
change  itemRollOut  itemRollOver 

Events inherited from class: mx.core.ScrollView
scroll 

Events inherited from class: mx.core.View
childCreated  childDestroyed  childIndexChanged 

Events inherited from class: mx.core.UIComponent
focusIn  focusOut  invalid  keyDown  keyUp  valid  valueCommitted 

Events inherited from class: mx.core.UIObject
creationComplete  dragComplete  dragDrop  dragEnter  dragExit  dragOver  draw  effectEnd  effectStart  hide  hideToolTip  initialize  load  mouseChangeSomewhere  mouseDown  mouseDownSomewhere  mouseMove  mouseMoveSomewhere  mouseOut  mouseOver  mouseUp  mouseUpSomewhere  move  resize  show  showToolTip  unload 



Styles
alternatingRowColors Type: Array   CSS Inheritance: yes
Colors for rows in an alternating pattern. Value can be an Array of two of more colors. Only used if backgroundColor is not specified
popupDuration Type: Number   Format: Time   CSS Inheritance: no
Duration in milliseconds of the transition as the menu opens. The value 0 specifies no transiton. The default value is 150.
rollOverColor Type: Number   Format: Color   CSS Inheritance: yes
Color of the background when the menu item is rolled over. The default value is 0x0EFFD6.
selectionColor Type: Number   Format: Color   CSS Inheritance: yes
Color of the background when the menu item is selected. The default value is 0x0DFFC1.
selectionDisabledColor Type: Number   Format: Color   CSS Inheritance: yes
Color The default value is 0xDDDDDD.
selectionEasing Type: String   CSS Inheritance: no
Reference to an easing equation (function) used for controlling programmating tweening.
textIndent Type: Number   Format: Length   CSS Inheritance: yes
Offset of the first line of text from the left side of the container. The default vlue is 0.
textRollOverColor Type: Number   Format: Color   CSS Inheritance: yes
The default value is 0x02B333C.
textSelectedColor Type: Number   Format: Color   CSS Inheritance: yes
The default value is 0x005F33.

Styles inherited from class mx.core.UIComponent
backgroundAlpha   backgroundColor   backgroundDisabledColor   backgroundImage   backgroundSize   barColor   borderCapColor   borderColor   borderSides   borderStyle   borderThickness   cornerRadius   disabledColor   dropShadow   errorColor   fillColors   highlightColor   modalTransparency   scrollTrackColor   selectedFillColors   shadowCapColor   shadowColor   shadowDirection   shadowDistance   symbolBackgroundColor   symbolBackgroundDisabledColor   symbolBackgroundPressedColor   symbolColor   symbolDisabledColor   themeColor  

Styles inherited from class mx.core.UIObject
color   fontFamily   fontSize   fontStyle   fontWeight   horizontalGap   leading   marginLeft   marginRight   textAlign   textDecoration   textIndent   verticalGap  



Constructor Detail

Menu

Menu( )

Constructor



Method Detail

addMenuItem

addMenuItem( arg: Object) :  Object

Appends a menu item to the end of this menu.

Parameters
    arg: Object - May be one of the following: a String, to be used as the item's label; an Object, whose properties are copied into the resulting XMLNode's attributes; an XMLNode, used directly; or an XML instance whose firstChild will be cloned and used.

Returns
     XMLNode that carries a representation of the menu item's state.


addMenuItemAt

addMenuItemAt( index: Number, arg: Object) :  Object

Inserts an item into this menu at a specified location.

Parameters
    index: Number - Index where the item should be inserted. An index of 0 is the first item.
    arg: Object - May be one of the following: a String, to be used as the item's label; an Object, whose properties are copied into the resulting XMLNode's attributes; an XMLNode, used directly; or an XML instance whose firstChild is cloned and used.

Returns
     XMLNode carrying a representation of the menu item's state


createMenu

static  createMenu( parent, mdp, initObj)

Returns the Menu instance described by the given MenuDataProvider, and places the instance in the given parent container. It does not display it, it just creates the instance so you can modify it if you need to before it is displayed. To display the menu, call the Menu.show() method.

Parameters
    parent - A UIObject to use as a starting point for the PopUpManager. The menu may not actually be parented by this UIObject. The PopUpManager will look for a valid top-level Container to use as the parent.
    mdp - MenuDataProvider on which to base the menu.
    initObj - An object of properties or MXML attributes to be set.

Returns
     Menu instance


getMenuItemAt

getMenuItemAt( index: Number) :  Object

Get a reference to an item from this menu. An index of 0 is the first item.

Parameters
    index: Number - Index of the item to retrieve.

Returns
     Reference to the XMLNode that was removed.


getRootMenu

getRootMenu( ) :  mx.controls.Menu

From any menu, walks up the parent menu chain and finds the root menu.


hide

hide( ) :  Void

If the Menu is visible, hide it and any visible submenus.


indexOf

indexOf( item: Object) :  Number

Returns the index of an item in this menu. If the item does not belong to this menu, it returns undefined.

Parameters
    item: Object - Target item.

Returns
     Index of the item, or undefined.


isItemEnabled

static  isItemEnabled( itm: Object) :  Boolean

If true, item is enabled. Convenience method for when you have a reference to an item that is deep in the hierrarchy. Otherwise you have to walk the hierarchy to get to the menu first

Parameters
    itm: Object - Item whose state to determine.


isItemSelected

static  isItemSelected( itm: Object) :  Boolean

If true, item is selected. An item is selected if it is a check or radio item and it is in the selected state, or the item represents a submenu and that submenu is visible, or the user is keyboard navigating through the menu and has navigated to that menu item. Convenience method for when you have a reference to an item that is deep in the hierrarchy. Otherwise you have to walk the hierarchy to get to the menu first

Parameters
    itm: Object - Item whose state to determine.


measure

measure( ) :  Void

Measures the menu items to calculate its height and width. Does not take into account the position and size of submenus.


removeAll

removeAll( ) :  Object

Removes all items from the menu.


removeMenuItem

removeMenuItem( item: Object) :  Object

Removes an item from the menu. If the item does not belong to this Menu, has no effect nothing and returns undefined.

Parameters
    item: Object - Item to remove.

Returns
     Reference to the XMLNode that was removed, or undefined if the item does not belong to this Menu instance.


removeMenuItemAt

removeMenuItemAt( index: Number) :  Object

Removes the item at a given location from the menu. An index of 0 is the first item. If there is no item at the given location, has no effect and returns undefined.

Parameters
    index: Number - Index of the item to remove.

Returns
     Reference to the XMLNode that was removed, if any.


setMenuItemEnabled

setMenuItemEnabled( item: Object, enable: Boolean) :  Void

Marks a menu item as enabled (or not). A disabled menu item cannot be selected.

Parameters
    item: Object - Target item.
    enable: Boolean - Boolean that indicates whether or not the item is enabled.


setMenuItemSelected

setMenuItemSelected( item: Object, select: Boolean) :  Void

Marks an item as selected (or not). The item must be a check or radio item, otherwise will have no effect.

Parameters
    item: Object - Target item.
    select: Boolean - Boolean that indicates whether or not the item is selected


show

show( x: Number, y: Number) :  Void

If the Menu isn't visible, place the top left corner at the given coordinates, resize the menu as needed, and make it visible. The x and y arguments of the show() method specify the coordinates of the top left corner of the Menu control relative to the parent application of the control, not necessarily to the direct parent of the control. Therefore, if the Menu control is in an HBox container nested within a Panel container, the coordinates are relative to the Application container, not to the HBox container.

Parameters
    x: Number - Horizontal location of the top left corner (optional).
    y: Number - Vertical location of the top left corner (optional).



Property Detail

version

static  version: String  

Version string for this class.


Examples
SimpleMenuExample.mxml
<?xml version="1.0"?>
<!-- Simple example to demonstrate the Menu control -->
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" backgroundColor="#FFFFFF">

    <mx:Script>
        <![CDATA[
       
       import mx.controls.Menu;
       var myMenu:Menu;
   
       // Menu object is created and Displayed using this function.
       function Show()
       {
           myMenu= Menu.createMenu(panel,myMenuData);
		   myMenu.x = 300;
		   myMenu.y = 100;
           myMenu.show();
           var menuEventHandler=new Object();
           menuEventHandler.change=function(event)
           {
              dispatchEvent({type:event.menuItem.attributes.eventName,target:this});
           }
       
           var menuEventDelegate= mx.utils.Delegate.create(this,menuEventHandler);
           myMenu.addEventListener("change",menuEventDelegate);

       }
    
      ]]>
    </mx:Script>

    <mx:XML id="myMenuData">
        <menuitem label="MenuItem A">
            <menuitem label="SubMenuItem 1-A" eventName="copy"/>
            <menuitem label="SubMenuItem 2-A" eventName="paste"/>
        </menuitem>
    </mx:XML>

    <mx:Panel id="panel" title="Menu Panel">
        <mx:Button id="mybutton" label="Open Menu-Popup" click="Show()"/>
    </mx:Panel>

</mx:Application>   
       




Comments


don4sin said on Feb 15, 2005 at 1:56 PM :
Delegate.create requires a Function for the 2nd parameter. In the example above, change:
var menuEventDelegate= mx.utils.Delegate.create(this,menuEventHandler);
to:
var menuEventDelegate= mx.utils.Delegate.create(this,menuEventHandler.change);
No screen name said on Sep 14, 2005 at 9:36 PM :
I believe either the docs are wrong for the menuHide event or there is a bug in the engine. This sample code should detect when the Options cascading menu is hidden, but instead menuHide lists undefined unless you are on a top-level menu bar menu. According to the menuHide event documentation, the event should contain a reference to menuItem, defined as the selected menu item. As my sample code demonstrates, if the menu item is a top-level menu item positioned on the menu bar, the menuItem property is properly populated. However, if it is a cascading/nested menu then the menuItem is undefined. Clearly, this shouldn't be the case if the documentation is to be taken literally. So either there is a bug in the engine or a bug in the docs. Can you clarify which it is please?




<?xml version="1.0"?>
<!-- Simple example to demonstrate the Menu control -->
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" backgroundColor="#FFFFFF">

<mx:Script>
<![CDATA[

import mx.controls.Menu;

// Menu object is created and Displayed using this function.
function config()
{
var fileMenu = menuBar1.addMenu("File", undefined);

fileMenu.addMenuItem("Print");

var toolsMenu = menuBar1.addMenu("Tools", undefined);

var optionsMenu = toolsMenu.addMenuItem("Options");

var prefsMenu = toolsMenu.addMenuItem("Preferences...");
var layoutMenu = toolsMenu.addMenuItem("Layout");

var cascade1 = optionsMenu.addMenuItem("Option 1");
var cascade2 = optionsMenu.addMenuItem("Option 2");

toolsMenu.addEventListener("menuHide",
mx.utils.Delegate.create(this, menuEventTrackHide));

}

// Define the event handler for the Menu events.
function menuEventTrackHide(event) {
eventTracker.addItem(event.menuItem.attributes.label + " Hidden");
}

]]>
</mx:Script>

<mx:XML id="myMenuData">
<menuitem label="MenuItem A">
<menuitem label="SubMenuItem 1-A" eventName="copy"/>
<menuitem label="SubMenuItem 2-A" eventName="paste"/>
</menuitem>
</mx:XML>

<mx:MenuBar id="menuBar1" initialize="config()"/>



<mx:List id="eventTracker" width="300"/>


</mx:Application>
Robin Hilliard said on Jan 12, 2006 at 9:02 PM :
Use addMenuItem(), not addItem().
fluffysocks said on Mar 24, 2006 at 11:23 AM :
I'm not able to get the 'rowCount' property to return anything but '0' for my menu. How can I get the rowCount of my menu or get the height of it (neither or which is returning anything but '0')?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/asdocs_en/mx/controls/Menu.html