Is it possible to create submenu in context menu (right click menu) in Adobe Flex?
Menu1 >
- Menu1.1
- Menu1.2
Menu2 >
- Menu2.1
- Menu2.2
- Menu2.3
Is it possible to create submenu in context menu (right click menu) in Adobe Flex?
Menu1 >
- Menu1.1
- Menu1.2
Menu2 >
- Menu2.1
- Menu2.2
- Menu2.3
No; it is one of the current limitation; I believe of the Flash Player.
In Adobe AIR you can add submenus to the context menu using the submenu property of the NativeMenuItem class.
An easy way to adding Sub-menu in AIR application
<?xml version="1.0" encoding="utf-8"?>
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="400"
creationComplete="panel1_creationCompleteHandler(event)"
rightClick="panel1_rightClickHandler(event)" title="Context Menu with Subitem">
<fx:Script>
<![CDATA[
import mx.controls.Alert
private var myContextMenu:ContextMenu = new ContextMenu();
protected function panel1_creationCompleteHandler(event:Event):void
{
this.contextMenu = myContextMenu;
}
protected function panel1_rightClickHandler(event:MouseEvent):void
{
var menuItem1:ContextMenuItem = new ContextMenuItem('Menu 1');
var menuItem2:ContextMenuItem = new ContextMenuItem('Menu 2');
myContextMenu.customItems = [menuItem1, menuItem2 ];
var subMenuItem1:ContextMenuItem = new ContextMenuItem('Sub- Menu 1');
subMenuItem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemClick);
var subMenuItem2:ContextMenuItem = new ContextMenuItem('Sub- Menu 2');
subMenuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemClick2);
var myContextSubMenu:ContextMenu = new ContextMenu();
myContextSubMenu.customItems = [subMenuItem1, subMenuItem2];
menuItem1.submenu = myContextSubMenu;
}
protected function menuItemClick(event:Event):void
{
Alert.show('Sub-Menu 1 is clicked');
}
protected function menuItemClick2(event:Event):void
{
Alert.show('Sub-Menu 2 is clicked');
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:Panel>
Enjoy