<?xml version="1.0" encoding="utf-8"?> <gui:RCPModule xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:gui="cn.smartinvoke.gui.*" xmlns:rcp="cn.smartinvoke.rcp.*" layout="vertical" creationComplete="init()" width="474" height="257"> <mx:Script> <![CDATA[ import cn.smartinvoke.smartrcp.gui.control.CNativeMenuBuilder; import cn.smartinvoke.smartrcp.gui.module.CActionEvent; import mx.collections.ArrayCollection; import mx.controls.Menu; var nativeMenu:CNativeMenuBuilder=null; [Bindable] private var gridData:ArrayCollection=new ArrayCollection(); function init():void{ var info:String="本模块演示smartrcp的右键功能,第一个panel为本地右键菜单, 第二个为flex右键菜单"; smartrcpDemo.Instance.setInfo(info); //添加数据 for(var i:uint=0;i<20;i++){ gridData.addItem({col1:"col1"+i,col2:"col2"+i,col3:"col3"+i}); } this.addNativeMenu(); this.createFlexMenus(); } //创建本地右键菜单 function addNativeMenu():void{ nativeMenu=new CNativeMenuBuilder(this.flashContainer); nativeMenu.initAction(this.cActions1); nativeMenu.initMenu(this.menuRelation); nativeMenu.addListener(this.onMenuClick,this); this.contextMenuManager.addNativeMenu(this.dataGrid,nativeMenu); } //创建flex右键菜单 var menu1: Menu=null; function createFlexMenus():void{ menu1=Menu.createMenu(this, flexMenuData,false); menu1.labelField="@label"; this.contextMenuManager.addMenu(this.panel2,this.menu1); } var num:int=0; function onAddClick():void{ var action:CAction=new CAction(); action.actionId="add"+num; action.text="添加的菜单项"+num; num++; this.nativeMenu.addAction(action); this.nativeMenu.addMenuItem(action.actionId,"子菜单/子菜单1"); } function onMenuClick(evt:CActionEvent):void{ this.infoLabel.text="你点击了"+evt.actionId+" path="+evt.path; //nativeMenu.removeMenuItem(evt.actionId,evt.path); } function onDelClick():void{ this.contextMenuManager.removeMenu(this.panel1); } ]]> </mx:Script> <mx:XML format="e4x" id="flexMenuData"> <root> <menuitem label="flex右键菜单"/> </root> </mx:XML> <rcp:CMenuRelation id="menuRelation"> <rcp:actions> <mx:String>a1</mx:String> <mx:String>-</mx:String> <mx:String>a2</mx:String> <mx:String>-</mx:String> <rcp:CMenuRelation label="子菜单"> <rcp:actions> <mx:String>a3</mx:String> <mx:String>a4</mx:String> <rcp:CMenuRelation label="子菜单1"> <rcp:actions> <mx:String>a5</mx:String> </rcp:actions> </rcp:CMenuRelation> </rcp:actions> </rcp:CMenuRelation> </rcp:actions> </rcp:CMenuRelation> <mx:Array id="cActions1"> <rcp:CAction actionId="a1" type="{CAction.AS_RADIO_BUTTON}" text="测试2" toolTip="toolTipTest1..."/> <rcp:CAction actionId="a2" type="{CAction.AS_RADIO_BUTTON}" text="测试3" toolTip="toolTipTest2..."/> <rcp:CAction actionId="a3" type="{CAction.AS_RADIO_BUTTON}" text="测试4" toolTip="toolTipTest3..."/> <rcp:CAction actionId="a4" type="{CAction.AS_RADIO_BUTTON}" text="a4" toolTip="toolTipTest3..."/> <rcp:CAction actionId="a5" type="{CAction.AS_RADIO_BUTTON}" text="a5" toolTip="toolTipTest3..."/> </mx:Array> <mx:Panel id="panel1" title="本地右键菜单" cornerRadius="0" horizontalAlign="center" verticalAlign="middle" styleName="opaquePanel" width="100%" height="100%"> <mx:DataGrid id="dataGrid" width="100%" height="100%" dataProvider="{gridData}"> <mx:columns> <mx:DataGridColumn headerText="列 1" dataField="col1"/> <mx:DataGridColumn headerText="列 2" dataField="col2"/> <mx:DataGridColumn headerText="列 3" dataField="col3"/> </mx:columns> </mx:DataGrid> </mx:Panel> <mx:Panel id="panel2" title="flex右键菜单" cornerRadius="0" horizontalAlign="center" verticalAlign="middle" styleName="opaquePanel" width="100%" height="100%"> <mx:Label id="infoLabel" width="100%"/> </mx:Panel> </gui:RCPModule>