In my application I need the user to right-click on the rows of the datagrid, so I created a function that creates a context menu. So when the user right-clicks on the row there is a menu bar and he clicks a choice to open an alert window. However my datagrid is inside a title window that is inside the panel that holds the map. If the data is inside these controls the function to create a context menu does not work. What do I need to change on the code to make it that possible? I have to have the datagrid at least inside the title window. Thank you for any help!!!
private function init():void
{
var dataGridContextMenu:ContextMenu = new ContextMenu();
dataGridContextMenu.hideBuiltInItems();
dataGridContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,
menuSelectHandler);
dataGrid.contextMenu = dataGridContextMenu;
}
private function menuSelectHandler(event:ContextMenuEvent):void
{
var displayObject:DisplayObject = event.mouseTarget as DisplayObject;
while (!(displayObject is IDataRenderer) && !(displayObject == dataGrid))
{
displayObject = displayObject.parent;
}
var data:Object;
if (displayObject is IDataRenderer)
data = IDataRenderer(displayObject).data;
var customItems:Array = [];
if (data)
{
var contextMenuItem:ContextMenuItem = new ContextMenuItem(data.name, false, false);
customItems.push(contextMenuItem);
var contextMenuItem3:ContextMenuItem = new ContextMenuItem("TEST", true, true);
customItems.push(contextMenuItem3);
contextMenuItem3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect)
}
var menu:ContextMenu = ContextMenu(event.target);
menu.customItems = customItems;
}
private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void {
var obj:String = dataGrid.selectedIndex.toString()
Alert.show("Property A: + Property B" + obj , Alert.OK);
}