The TreeEvent class is used in the dispatching of all nonstandard events (i.e., built-in Flash events) available for the AdvancedTree. It provides a single additional property, node, which is the TreeNode instance that has been acted on for or that caused the event. It also contains a number of constants that can be used for setting up event listeners.
| Property Name | Class | Value | Description |
| ANIMATION_COMPLETE | String | "nodeAnimationComplete" | Event dispatched when an animated tree comples its animation of opening or closing nodes |
| DATA_LOAD | String | "treeDataLoad" | Event dispatched when the tree completes the loading of any external data. |
| DATA_LOAD_PREPROCESS | String | "treeDataLoadPreprocess" | Event dispatched when the tree has loaded external data but has yet to process it. This can be used to clean up the data. |
| HORIZONTAL_SCROLL | String | "horizontalScroll" | Event dispatched when the tree is scrolled using the horizontal scrollbar. |
| NODE_CLOSE | String | "nodeClose" | Event dispatched when a node is closed. |
| NODE_DESELECT | String | "nodeDeselect" | Event dispatched when a node is deselected. |
| NODE_DRAG | String | "nodeDrag" | Event dispatched when a node drag action begins. |
| NODE_DROP | String | "nodeDrop" | Event dispatched when a node is dropped within the tree after a drag action. |
| NODE_DROP_PRECOMMIT | String | "nodeDropPrecommit" | Event dispatched when a node is dropped within the tree after a drag action, but before the data is changed. This allows for the drop to be prevented. |
| NODE_DOUBLECLICK | String | "nodeDoubleclick" | Event dispatched when a node is doubleclicked with the mouse. |
| NODE_OPEN | String | "nodeOpen" | Event dispatched when a node is opened. |
| NODE_PRESS | String | "nodePress" | Event dispatched when a node is clicked with the mouse, before the release of the mouse. |
| NODE_RELEASE | String | "nodeRelease" | Event dispatched when the mouse is released over a node after a press action. |
| NODE_RENAME | String | "nodeRename" | Event dispatched when a node label is edited. |
| NODE_RESIZE | String | "nodeResize" | Event dispatched when a node is resized, generally after an edit. |
| NODE_ROLLOUT | String | "nodeRollout" | Event dispatched when the mouse is rolled off a node. |
| NODE_ROLLOVER | String | "nodeRollover" | Event dispatched when the mouse is rolled over a node. |
| NODE_SELECT | String | "nodeSelect" | Event dispatched when a node is selected. |
| VERTICAL_SCROLL | String | "verticalScroll" | Event dispatched when the tree is scrolled using the vertical scrollbar. |
The AdvancedTree component broadcasts events to which the developer can have objects subscribe, and thus receive notification when an event occurs. It extends flash.events.EventDispatcher and so uses the same event model as the core ActionScript classes that also extend flash.events.EventDispatcher. Please refer to Adobe's documentation on adding and removing event listeners and setting up handlers for events.
The only difference with the AdvancedTree is that, by default, it adds handlers using weak references, whereas the Adobe classes do not. This means that if you wish to pass an anonymous function as a handler to the tree, you will need to explictly pass false as the useWeakReference parameter. In general, though, you will not need to worry about the reference if you are using methods of a class.
Several of the events dispatched by the AdvancedTree component are cancelable or allow you to prevent their default actions from being run. First, the DATA_LOAD_PREPROCESS event allows you alter the data that has been loaded into the tree from an external source and prevent the tree from using the data as is. To take advantage of this event, you should access the data from the TreeNode instance passed with the event, then call preventDefault() on the event. After you alter the data as you require, you can pass the altered XML to the tree's populate() method.
private function onDataLoadPreprocess(event:TreeEvent):void {
event.preventDefault();
var xml:String = event.node.toXML();
xml = xml.replace(new RegExp("newline", "g"), "\n");
_tree.populate(new XML(xml));
}
private function onNodeDropPrecommit(event:TreeEvent):void {
var droppedNode:TreeNode = event.node;
var dropContext:DropContext = _tree.dropContext;
if (dropContext.node.nodeName == "page") {
pEvent.preventDefault();
}
}