PDA

View Full Version : Tree,XML, and AutoOpen Nodes


nytyme
08-31-2004, 11:14 PM
Is it possible to have an xml file that will cause a tree to open it's branches?

here's my_xml

<node label="1">
<node label="1.1">
<node label="1.1.1"></node>
<node label="1.1.2"></node>
<node label="1.1.3"></node>
<node label="1.1.4"></node>
</node>
<node label="1.2">
<node label="1.2.1"></node>
<node label="1.2.2"></node>
</node>
</node>


when i set myTree.dataProvider = my_xml, it looks like this:

+1

what i'd like is for it too look like this:

-1
-1.1
- 1.1.1
- 1.1.2
- 1.1.3
- 1.1.4
- 1.2
- 1.2.1
- 1.2.2
Any ideas?

I've been googling and searching the forums, but so far to no avail.

petefs
08-31-2004, 11:58 PM
You can't have an XML file actually open the node. You can, however, write a function in flash to open all the nodes.

the tree has a setIsOpen() method, which I believe must be followed by a nodeOpen event broadcast (not sure).

so you'll want to loop through through the nodes and set them all to open something like this:


myTree.dataProvider = my_xml;
for (var i = 0; i<myTree.length; i++) {
var node:XMLNode = myTree.getTreeNodeAt(i);
myTree.setIsOpen(node, true, false);
// myTree.dispatchEvent({type: "nodeOpen"}); // probably not necessary
}


If you ever wanted only certain nodes to open, you can add a property in the xml file and check against that in the script. for example:

<node label="1.2" defaultState="open">

and then the code would read something like this:


myTree.dataProvider = my_xml;
for (var i = 0; i<myTree.length; i++) {
var node:XMLNode = myTree.getTreeNodeAt(i);
if(node.defaultState=="open")
{
myTree.setIsOpen(node, true, false);
// myTree.dispatchEvent({type: "nodeOpen"}); // probably not necessary
}
}


not tested, but it should point you in the right direction! any other Q's fire em off. I've found the Tree component to be rather buggy when used in more than a rudimentary manner : )