Custom “context menu” in flex

前提是你 提交于 2019-12-06 11:20:01

If you're talking about a true contextual menu (the ones that shows up on right click), you might want to use the ContextMenu and ContextMenuItems class.

Something like that (in a <mx:Script> block) :

    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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!