We can enable and disable the context menu option from the context menu. In below example is very easy way to enable and disable the context menu option based on the context menu selection. Lets see the below example and enjoy
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInit()">
<mx:Script>
<![CDATA[
import mx.managers.FocusManager;
import mx.core.UIComponent;
private var _spr:Sprite;
private var _contextMenu:ContextMenu;
private function onInit():void
{
var ui:UIComponent = new UIComponent();
_spr = new Sprite();
_spr.graphics.clear();
_spr.graphics.beginFill(0xFF0000,0.8);
_spr.graphics.drawRect(0,0,200,200);
_spr.graphics.endFill();
ui.addChild(_spr);
_spr.x = 20;
_spr.y = 20;
addChild(ui);
loadContextMenu();
}
private function loadContextMenu():void
{
_contextMenu = new ContextMenu();
_contextMenu.hideBuiltInItems();
var _selAll:ContextMenuItem = new ContextMenuItem("Select All Hotspot");
var _deSelAll:ContextMenuItem = new ContextMenuItem("Deselect All Hotspot");
var _delAll:ContextMenuItem = new ContextMenuItem("Delete All Hotspot");
_contextMenu.customItems.push(_selAll);
_contextMenu.customItems.push(_deSelAll);
_contextMenu.customItems.push(_delAll);
_contextMenu.customItems[1].enabled = false;
_contextMenu.customItems[2].enabled = false;
_selAll.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelect);
_delAll.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelect);
_deSelAll.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelect);
_spr.contextMenu = _contextMenu;
}
private function menuItemSelect(evt:ContextMenuEvent):void
{
var _custMenu:ContextMenuItem = evt.target as ContextMenuItem;
if(_custMenu.caption == "Select All Hotspot")
{
_contextMenu.customItems[0].enabled = false;
_contextMenu.customItems[1].enabled = true;
_contextMenu.customItems[2].enabled = true;
}
else
{
_contextMenu.customItems[0].enabled = true;
_contextMenu.customItems[1].enabled = false;
_contextMenu.customItems[2].enabled = false;
}
}
]]>
</mx:Script>
</mx:Application>