Reputation: 183
Is there any way to know the parent/component which initiates context menu?
I have a panel which contains different custom components. i want to open respective popup window of custom component from context menu when user right click on the respective component.
How can i find the parent custom component which initiates context menu?
for ex:
custom compoent: 1. Label, 2. Buttom
context menu Item: properties
On right click over 'Label' opens a context menu which has item 'properties', on clicking properties it should open custom popoup window showing properties of Label. similarly, for Button.
I am trying to listen Event on click of context menu, but it is not useful.
what is the correct way to achieve this?
Upvotes: 0
Views: 557
Reputation: 76750
Try adding a listener for ContextMenuEvent.MENU_SELECT to the actual contextMenu
property on each of the components. In the handler you can do something like:
protected function contextMenuEventHandler(cme:ContextMenuEvent):void
{
var props:ContextMenuItem = new ContextMenuItem("Properties");
props.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function (event:ContextMenuEvent):void
{
Alert.show(cme.mouseTarget.toString());
});
cme.contextMenuOwner.contextMenu.customItems.push(props);
}
That's one way of doing it. Personally, I usually make the custom context menus ahead of time, and set them on each component in the MXML. However, doing it dynamically (as above) might be better in some circumstances.
Upvotes: 1