Tree.addTreeNode()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

Usage 1:

treeInstance.addTreeNode(label [, data])

Usage 2:

treeInstance.addTreeNode(child)

Parameters

label A string that displays the node, or an object with a label field (or whatever label field name is specified by the labelField property).

data An object of any type that is associated with the node. This parameter is optional.

child Any XMLNode object.

Returns

The added XML node.

Description

Method; adds a child node to the tree. The node is constructed either from the information supplied in the label and data parameters (Usage 1), or from the prebuilt child node, which is an XMLNode object (Usage 2). Adding a preexisting node removes the node from its previous location.

Calling this method refreshes the view.

Example

The following example creates two Tree components with a node for each one, 1st Local Folders and 2nd Local Folders, respectively. Then it adds the tree node (2nd Local Folders) from the second Tree to the first Tree and also adds a new node, Inbox.

You must first add the component to the document library by dragging a Tree component to the Stage and then deleting it; then add the following code to Frame 1.

TIP

First try this example without the two addTreeNode() statements at the end; then try the full example.

/**
 Requires:
  - Tree component in library
*/

import mx.controls.Tree;

this.createClassObject(Tree, "first_tr", 10);
first_tr.setSize(200, 100);

this.createClassObject(Tree, "second_tr", 20);
second_tr.setSize(200, 100);
second_tr.move(0, 120);

var trDP_xml:XML = new XML("<node label='1st Local Folders'><node label='Inbox' data='0'/><node label='Outbox' data='1'/></node>");
first_tr.dataProvider = trDP_xml;

var trDP2_xml:XML = new XML("<node label='2nd Local Folders'><node label='Outbox' data='0'/><node label='Outbox' data='1'/></node>");
second_tr.dataProvider = trDP2_xml;

// Add the node from second_tr to first_tr.
first_tr.addTreeNode(second_tr.getTreeNodeAt(0));

// Add node to first_tr.
first_tr.addTreeNode("Inbox", "data");