};
myTree.addEventListener("change", treeListener);
This code creates an XML object called
XML data source. The code then defines an
property of the
information about the XML object, see its entry in Flash ActionScript Language Reference.
Create a new file called treeXML.xml in a text editor.
5.
Enter the following code in the file:
6.
<node>
<node label="Mail">
<node label="INBOX"/>
<node label="Personal Folder">
<node label="Business" isBranch="true" />
<node label="Demo" isBranch="true" />
<node label="Personal" isBranch="true" />
<node label="Saved Mail" isBranch="true" />
<node label="bar" isBranch="true" />
</node>
<node label="Sent" isBranch="true" />
<node label="Trash"/>
</node>
</node>
Select Control > Test Movie.
7.
In the SWF file, you can see the XML structure displayed in the tree. Click items in the tree to
see the
trace()
panel.
To use the TreeDataProvider class to create XML in Flash while authoring:
In Flash, select File > New and select Flash Document.
1.
Drag an instance of the Tree component onto the Stage.
2.
Select the Tree instance and in the Property inspector, enter the instance name myTree.
3.
In the Actions panel on Frame 1, enter the following code:
4.
var myTreeDP:XML = new XML();
myTreeDP.addTreeNode("Local Folders", 0);
// Use XML.firstChild to nest child nodes below Local Folders
var myTreeNode:XMLNode = myTreeDP.firstChild;
myTreeNode.addTreeNode("Inbox", 1);
myTreeNode.addTreeNode("Outbox", 2);
myTreeNode.addTreeNode("Sent Items", 3);
myTreeNode.addTreeNode("Deleted Items", 4);
// Assign the myTreeDP data source to the myTree component
myTree.dataProvider = myTreeDP;
// Set each of the four child nodes to be branches
for (var i = 0; i<myTreeNode.childNodes.length; i++) {
var node:XMLNode = myTreeNode.getTreeNodeAt(i);
myTree.setIsBranch(node, true);
}
764
Chapter 6: Components Dictionary
instance to the new XML object when the XML loads. For more
myTree
statements in the
change
and calls the
myTreeDP
event handler that sets the
onLoad
event handler send the data values to the Output
method to load an
XML.load()
dataProvider
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?