flex4 自定义右键菜单

  1. <?xml version="1.0" encoding="utf-8"?>  
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
            layout="vertical"  
            verticalAlign="middle"  
            backgroundColor="white"  
            creationComplete="init()">  
       
        <mx:Script>  
            <![CDATA[ 
                import mx.controls.Alert; 
      
                [Bindable] 
                private var cm:ContextMenu; 
      
                private var alert:Alert; 
      
                private function init():void { 
                    var cmi:ContextMenuItem = new ContextMenuItem("菜单项",true); 
                    cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,contextMenuItem_menuItemSelect); 
                    var cmi1:ContextMenuItem = new ContextMenuItem("菜单项1",false); 
                    cmi1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,contextMenuItem_menuItemSelect1); 
                     
                    cm = new ContextMenu(); 
                    cm.hideBuiltinitems(); 
                    cm.customItems = [cmi,cmi1]; 
                    cm.addEventListener(ContextMenuEvent.MENU_SELECT,contextMenu_menuSelect); 
                } 
      
                private function contextMenu_menuSelect(evt:ContextMenuEvent):void { 
                    dataGrid.selectedindex = lastRolloverIndex; 
                } 
      
                private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void { 
                    var obj:Object = dataGrid.selectedItem; 
                    alert = Alert.show("Property A: " + obj.@propertyA + "\n" + "Property B: " + obj.@propertyB,obj.@label,Alert.OK); 
                } 
                private function contextMenuItem_menuItemSelect1(evt:ContextMenuEvent):void { 
                    var obj:Object = dataGrid.selectedItem; 
                    alert = Alert.show("Property A: " + obj.@propertyA + "\n" + "Property B: " + obj.@propertyB,Alert.OK); 
                } 
            ]]>  
        </mx:Script>  
       
        <mx:XML id="itemsXML">  
            <items>  
                <item label="Item 1" data="i001" propertyA="Item 1.A" propertyB="Item 1.B" />  
                <item label="Item 2" data="i002" propertyA="Item 2.A" propertyB="Item 2.B" />  
                <item label="Item 3" data="i003" propertyA="Item 3.A" propertyB="Item 3.B" />  
                <item label="Item 4" data="i004" propertyA="Item 4.A" propertyB="Item 4.B" />  
                <item label="Item 5" data="i005" propertyA="Item 5.A" propertyB="Item 5.B" />  
                <item label="Item 6" data="i006" propertyA="Item 6.A" propertyB="Item 6.B" />  
                <item label="Item 7" data="i007" propertyA="Item 7.A" propertyB="Item 7.B" />  
                <item label="Item 8" data="i008" propertyA="Item 8.A" propertyB="Item 8.B" />  
            </items>  
        </mx:XML>  
       
        <mx:Number id="lastRolloverIndex" />  
       
        <mx:DataGrid id="dataGrid"  
                width="400"  
                dataProvider="{itemsXML.item}"  
                 contextMenu="{cm}"  
                 itemRollover="lastRolloverIndex = event.rowIndex">  
            <mx:columns>  
                <mx:DataGridColumn id="labelCol"  
                        datafield="@label"  
                        headerText="Label:" />  
       
                <mx:DataGridColumn id="propACol"  
                        datafield="@propertyA"  
                        headerText="Property A:" />  
       
                <mx:DataGridColumn id="propBCol"  
                        datafield="@propertyB"  
                        headerText="Property B:" />  
            </mx:columns>  
        </mx:DataGrid>  
       
        <mx:Label text="{dataGrid.selectedItem.@label}" />  
       
    </mx:Application>  

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...