twaver-flex 右键菜单和右键选中网元

network.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, function(e:ContextMenuEvent):void{
//右键选中网元
var p:Point = new Point(e.mouseTarget.mouseX / network.zoom, e.mouseTarget.mouseY / network.zoom);
var datas:ICollection = network.getElementsByLocalPoint(p);
if (datas.count > 0) {
network.selectionModel.setSelection(datas.getItemAt(0));
}else{
network.selectionModel.clearSelection();
}

//定制右键菜单
var flexVersion:ContextMenuItem = new ContextMenuItem(DemoUtils.FLEX_SDK_VERSION, false, false);
        var playerVersion:ContextMenuItem = new ContextMenuItem(DemoUtils.FLASH_PLAYER_VERSION, false, false);

if(network.selectionModel.count == 0){
       network.contextMenu.customItems = [flexVersion, playerVersion];
        }else{
       var item1:ContextMenuItem = new ContextMenuItem("Add New Alarm", true);
       item1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handler);
       var item2:ContextMenuItem = new ContextMenuItem("Add Acked Alarm");
       item2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handler);
       var item3:ContextMenuItem = new ContextMenuItem("Clear Alarm");
       item3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handler);
                  
       network.contextMenu.customItems = [flexVersion, playerVersion, item1, item2, item3, item4, item5, item6];       
}        
    });

你可能感兴趣的:(Flex,Flash)