views:

457

answers:

2

I would like to add a custom context menu with line separators, but can't really figure out how. What I need:

<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>
A: 

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;
Zed-K