ActionScript 2.0 Components Language Reference |
|
|
|
| Tree component > Tree.nodeOpen | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
var listenerObject:Object= new Object();listenerObject.nodeOpen = function(eventObject:Object) {// Insert your code here.};treeInstance.addEventListener("nodeOpen",listenerObject);
Event; broadcast to all registered listeners when a user opens a node on a Tree component.
Components use a dispatcher/listener event model. The Tree component dispatches a nodeOpen event when a node is clicked open by a user; the event is handled by a function, also called a handler, that is attached to a listener object (listenerObject) that you create. You call the addEventListener() method and pass it the name of the handler as a parameter.
When the event is triggered, it automatically passes an event object (eventObject) to the handler. Each event object has properties that contain information about the event. You can use these properties to write code that handles the event. The Tree.nodeOpen event's event object has one additional property: node (the XML node that was opened).
For more information, see EventDispatcher class.
The following example adds two nodes to the Tree instance my_tr, and then creates two listener objects, one for nodeOpen events and one for nodeClose events. When these events occur, the listener functions call trace statements to display the event and the affected node in the Output panel.
You must first add an instance of the Tree component to the Stage and name it my_tr; then add the following code to Frame 1.
/**
Requires:
- Tree component on Stage (instance name: my_tr)
*/
var my_tr:mx.controls.Tree;
my_tr.setSize(200, 100);
var trDP_xml:XML = new XML("<node label='1st Local Folders'><node label='Inbox' data='0'/><node label='Outbox' data='1'/></node><node label='2nd Local Folders'><node label='Inbox' data='2'/><node label='Outbox' data='3'/></node>");
my_tr.dataProvider = trDP_xml;
// Create listener object.
var trListener:Object = new Object();
trListener.nodeOpen = function(evt_obj:Object){
trace("Node opened\n" + evt_obj.node);
trace("\n");
}
trListener.nodeClose = function(evt_obj:Object){
trace("Node closed\n" + evt_obj.node);
trace("\n");
}
// Add listeners.
my_tr.addEventListener("nodeOpen", trListener);
my_tr.addEventListener("nodeClose", trListener);
|
|
|
|