在上下文菜单中创建子菜单

时间:2010-05-27 00:02:41

标签: flex adobe contextmenu

是否可以在Adobe Flex中的上下文菜单(右键菜单)中创建子菜单?

Menu1 >
  - Menu1.1
  - Menu1.2
Menu2 >
  - Menu2.1
  - Menu2.2
  - Menu2.3

2 个答案:

答案 0 :(得分:0)

没有;这是目前的局限之一;我相信Flash Player。

在Adobe AIR中,您可以使用NativeMenuItem类的子菜单属性将子菜单添加到上下文菜单中。

答案 1 :(得分:-1)

在AIR应用程序中添加子菜单的简便方法

    <?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>

享受