R – How to Fire tree itemClick event on, setting Tree.selectedItem in Flex3 Air

actionscript-3airapache-flex

I am working on Air application,i had a problem on Tree control.

Iam adding nodes for the tree dynamically, while adding nodes to the tree i am setting

Tree.selectedItem as present added node. after that i need to fire Tree.itemClick event handler method also.

how can i call event handler method as a common method. in Flex3

Best Answer

You can either call the method like you call any other method (pass null for the argument) or you can call dispatchEvent on the Tree to invoke the event handler automatically.

If the event handler function is added through mxml and is not expecting the event as its argument, or it is added with AS but not actually using the event parameter, you can call it like you call any other function.

private function itemClickHandler(event:ListEvent):void
{
  //code doesn't use event
}
//call it with a null
itemClickHandler(null);

//OR

private function itemClickHandler(event:ListEvent = null):void
{
  //code doesn't use event
}
itemClickHandler();