Responding to Events

Events Broadcast

Event Description Parameters Sent
select Fired whenever the node selection in the tree changes. node : TreeNode (the selected node)
deselect Fired whenever nodes are deselected in the tree. node : TreeNode (the last node deselected)
doubleclick Fired whenever a node is doubleclicked. node : TreeNode (the clicked node)
release Fired whenever a node's movie clip is released after being clicked with mouse. node : TreeNode (the node clicked, then released)
press Fired whenever a node's movie clip is clicked with the mouse. node : TreeNode (the clicked node)
rollOver Fired whenever a node's movie clip is rolled over by the mouse. node : TreeNode (the node rolled over)
rollOut Fired whenever the mouse leaves a node's movie clip after rolling over it. node : TreeNode (the node rolled out)
rename Fired whenever a node has been renamed by the user typing into its field. node : TreeNode (the node with name change)
drop Fired whenever a node is dropped in the tree after being dragged by user. valid : Boolean (whether the drop is allowed)
node : TreeNode (the node dropped)
droppedObject : MovieClip (the movie clip containing the dropped node)
oldParent : TreeNode (the node that the dropped node originally had as parent)
newParent : TreeNode (the dropped node's new parent)

Broadcaster Model

The advancedTree component broadcasts events to which the developer can have objects subscribe, and thus receive notification when an event occurs. Handlers for a advancedTree instance's events are passed an information object containing a reference to the advancedTree instance as well as a parameters object containing one or more additional parameters. To create a listener for component events follow the following steps.
  1. Create a new object to subscribe to tree events, or alternatively use an existing object such as a movie clip instance.
  2. // creates a new object to subscribe to events
    var treeListener:Object = new Object();

    // creates a new object to subscribe to events (alternative)
    var treeListener:Object = {};

  3. Give the listener object appropriate handlers for the tree events. These can either correspond directly with the names of the events, or can have unique names that can be mapped to events when the object subscribes.
  4. // give listener to a select event handler for the tree's select event
    treeListener.select = function(infoObj:Object):Void {
      // infoObj.target == advancedTree instance broadcasting event
      // infoObj.parameters.node == TreeNode instance selected
      // all code dealing with selection should be placed within this handler
    };

    // give listener to a select event handler with a unique name for the tree's select event
    treeListener.onNodeSelect = function(infoObj:Object):Void {
      // infoObj.target == advancedTree instance broadcasting event
      // infoObj.parameters.node == TreeNode instance selected
      // all code dealing with selection should be placed within this handler
    };

  5. Subscribe the listener object to the appropriate events using the advancedTree instance's addEventListener method. The first parameter is the name of the event to which to subscribe. The second parameter is a reference to the listener. The third parameter, which is optional, is the name of the method to be called on the listener when the event is fired. If no method is named, then the advancedTree instance will by default call a handler on the listener with the same name as the event.
  6. // subscribe listener to the tree's select event
    // in this case, the handler "select" wil be called on treeListener
    tree.addEventListener("select", treeListener);

    // subscribe listener to the tree's select event
    // in this case, the handler "onNodeSelect" wil be called on treeListener
    tree.addEventListener("select", treeListener, "onNodeSelect");

  7. Removing event listeners is done with the advancedTree's removeEventListener method, which requires the name of the event and the listener. No third parameter is required (nor used).
  8. // removes listener from the tree's select event
    tree.removeEventListener("select", treeListener);

  9. The complete code for subscribing to events is listed below.
  10. // uses default select handler for the tree's select event
    var treeListener:Object = {};
    treeListener.select = function(infoObj:Object):Void {
      // relevant code here
    };
    tree.addEventListener("select", treeListener);

    // uses custom handler for the tree's select event
    var treeListener:Object = {};
    treeListener.onNodeSelect = function(infoObj:Object):Void {
      // relevant code here
    };
    tree.addEventListener("select", treeListener, "onNodeSelect");

Specifying Custom Methods per Node