Sunday, 15 February 2009

Right click on Tree component, Flex 2

When we bind context menu to Tree component in Flex 2 and click on it with right mouse, we don't know which item has been picked by clicking right mouse button on it. There is a small workaround to solve the problem:

We have
<< mx:Tree id="myXMLTree" width="100%" height="100%" itemRollOver="updateCurrentSelectedItem(event)">>
component.

First of all we bind context menu to it by: myXMLTree.contextMenu = m_menu; Second, the idea is to hande itemRollOver event on a tree, to know on which item the cursor is pointed right now. So "itemRollOver" event handler hold it's value in global variable "selectedTreeItem" every time we roll mouse over any item of the tree we update
selectedTreeItem variable with current item.

public function updateCurrentSelectedItem(le:ListEvent):void {
selectedTreeItem = (le.itemRenderer.data as XML);
}

So when we handle rightClick on tree, we use selectedTreeItem global variable to know which item has been clicked when context menu has been called.

No comments:

Post a Comment