User Guide

Tree component (Flash Professional only) 765
This code creates an XML object called myTreeDP. Any XML object on the same frame as a
Tree component automatically receives all the properties and methods of the TreeDataProvider
interface. The second line of code creates a single root node called Local Folders. For detailed
information about the rest of the code, see the comments (lines preceded with
//) throughout
the code.
5.
Select Control > Test Movie.
In the SWF file, you can see the XML structure displayed in the tree. Click items in the tree to
see the
trace() statements in the change event handler send the data values to the Output
panel.
To use the ActionScript XML class to create XML:
1.
In Flash, select File > New and select Flash Document.
2.
Drag an instance of the Tree component onto the Stage.
3.
Select the Tree instance. In the Property inspector, enter the instance name myTree.
4.
In the Actions panel on Frame 1, enter the following code:
// Create an XML object
var myTreeDP:XML = new XML();
// Create node values
var myNode0:XMLNode = myTreeDP.createElement("node");
myNode0.attributes.label = "Local Folders";
myNode0.attributes.data = 0;
var myNode1:XMLNode = myTreeDP.createElement("node");
myNode1.attributes.label = "Inbox";
myNode1.attributes.data = 1;
var myNode2:XMLNode = myTreeDP.createElement("node");
myNode2.attributes.label = "Outbox";
myNode2.attributes.data = 2;
var myNode3:XMLNode = myTreeDP.createElement("node");
myNode3.attributes.label = "Sent Items";
myNode3.attributes.data = 3;
var myNode4:XMLNode = myTreeDP.createElement("node");
myNode4.attributes.label = "Deleted Items";
myNode4.attributes.data = 4;
// Assign nodes to the hierarchy in the XML tree
myTreeDP.appendChild(myNode0);
myTreeDP.firstChild.appendChild(myNode1);
myTreeDP.firstChild.appendChild(myNode2);
myTreeDP.firstChild.appendChild(myNode3);
myTreeDP.firstChild.appendChild(myNode4);
// Assign the myTreeDP data source to the Tree component
myTree.dataProvider = myTreeDP;
For more information about the XML object, see its entry in Flash ActionScript Language
Reference.
5.
Select Control > Test Movie.
In the SWF file, you can see the XML structure displayed in the tree. Click items in the tree to
see the
trace() statements in the change event handler send the data values to the Output
panel.