flex中的自定义“上下文菜单”

时间:2010-03-18 18:19:32

标签: flex actionscript-3 mxml

我想添加一个带行分隔符的自定义上下文菜单,但无法弄清楚如何。我需要的是:

<mx:List id="treeContextFile" visible="false" width="233" verticalScrollPolicy="off" includeInLayout="false">
        <mx:dataProvider>
            <mx:Array >
                <mx:String>Open</mx:String>
                <horizontal line here >
                <mx:String>Cut</mx:String>
                <mx:String>Copy</mx:String>
                <mx:String>Paste</mx:String>
                <horizontal line here >
                <mx:String>Rename</mx:String>
                <mx:String>Delete</mx:String>
                <horizontal line here >
                <mx:String>Properties</mx:String>
            </mx:Array>
        </mx:dataProvider>
    </mx:List>

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

如果您正在谈论真正的上下文菜单(右键单击显示的菜单),您可能需要使用ContextMenu和ContextMenuItems类。

类似的东西(在<mx:Script>块中):

    var cmiOpen  :ContextMenuItem = new ContextMenuItem( "Open" );
    var cmiCut   :ContextMenuItem = new ContextMenuItem( "Cut", true );
    var cmiCopy  :ContextMenuItem = new ContextMenuItem( "Copy" );
    var cmiPaste :ContextMenuItem = new ContextMenuItem( "Paste" );
    var cmiRename:ContextMenuItem = new ContextMenuItem( "Rename", true );
    var cmiDelete:ContextMenuItem = new ContextMenuItem( "Delete" );
    var cmiProps :ContextMenuItem = new ContextMenuItem( "Properties" );

    var cm:ContextMenu = new ContextMenu();
        cm.addItem( cmiOpen );
        cm.addItem( cmiCut );
        cm.addItem( cmiCopy );
        cm.addItem( cmiPaste );
        cm.addItem( cmiRename );
        cm.addItem( cmiDelete );
        cm.addItem( cmiProps );

    cmiOpen.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, openFunction );
    cmiCut.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, cutFunction );
    ...

    yourComponent.contextMenu = cm;

答案 2 :(得分:0)