View comments | RSS feed

Tree.setIsOpen()

Availability

Flash Player 6 (6.0 79.0).

Edition

Flash MX Professional 2004.

Usage

myTree.setIsOpen(node, open [, animate])

Parameters

node An XML node.

open A Boolean value that opens a node (true) or closes it (false).

animate A Boolean value that determines whether the opening transition is animated (true) or not (false). This parameter is optional.

Returns

Nothing.

Description

Method; opens or closes a node.

Example

The following code opens a node of myTree:

myTree.setIsOpen(myTree.getTreeNodeAt(1), true);

Comments


No screen name said on Jan 6, 2005 at 1:52 PM :
I answered my own question... No. At least not by design. So i made somthing that will do it. for my purposes. It only goes 2 levels down. L0 -> L1 -> selected item is the only structure it can handle as is. Im sure it could be recursively redesigned. But I'm at work, not playing at home. So if anyone wants to make this recursive, go ahead. I simply don't have the time :)

Anyhow.
Passing in a variable (in my case #this.issue#). I created the isOpen attribute, and set it to 1. You can do whatever you wish inside the if statement, like if(child_xml_final.attributes.id == _root.myvar). this function then searches the TreeDP for the item you wish to show. when the search is over, and your item is found, the function's loop indexes point to the folders that need to be opened. Below is the function in AS.
Its really simple, just hard to explain. Look below. it will become more clear for you.

function FindOpenIssue(rootXML) // rootXML is like "this.firstChild"
// which would put the root node as
// the starting point
{
rootElement_xml = rootXML; // get document's root node
for(i=0; i< rootElement_xml.childNodes.length; i++)
{
child_xml = rootElement_xml.childNodes[i];
for(j=0; j<child_xml.childNodes.length; j++) {
child_xml_Deeper = child_xml.childNodes[j];
for(k=0; k<child_xml.childNodes.length; k++)
{
child_xml_final = child_xml_Deeper.childNodes[k];
if(child_xml_final.attributes.isOpen)
{
//this line shows the labels of the folders and your selected item
trace(child_xml.attributes.label +":"+ child_xml_Deeper.attributes.label+":"+ child_xml_final.attributes.label)
myTree.setIsOpen(myTree.getTreeNodeAt(i), true);
myTree.setIsOpen(myTree.getNodeDisplayedAt(j+i+1), true);
myTree.selectedNode = child_xml_final;
}
}
}
}
}
twoei22 said on Jan 13, 2005 at 2:45 PM :
Actually It works but you have to ensure that the XML is loaded before you try to use it.
You put it into the myTreeDataProvider.onLoad function.

Here's a complete example:

---------------------------------

myTreeDataProvider = new XML();
myTreeDataProvider.ignoreWhite = true;
myTreeDataProvider.load("tree2.xml");
myTreeDataProvider.onLoad = function() {
myTree.dataProvider = myTreeDataProvider;
myTree.setIsOpen(myTree.getTreeNodeAt(0), true);
myTree.setIsOpen(myTree.getTreeNodeAt(0).getTreeNodeAt(1), true);
//To open Sub Sub level..
//myTree.setIsOpen(myTree.getTreeNodeAt(0).getTreeNodeAt(1).getTreeNodeAt(1), true);
};


myTreeListener = new Object();
myTreeListener.tree = myTree;
myTreeListener.change = function(eventObject) {
var theSelectedNode = eventObject.target.selectedNode;
var theSelectedNodeLabel = theSelectedNode.attributes.label;
var esLink = theSelectedNode.attributes.isLink;
var esBranch = this.tree.getIsBranch(theSelectedNode);
if (esBranch) {
if (this.tree.getIsOpen(theSelectedNode)) {
this.tree.setIsOpen(theSelectedNode, false, true);
} else {
this.tree.setIsOpen(theSelectedNode, true, true);
}
} else {
if (esLink) {
var theSelectedNodeURL = theSelectedNode.attributes.url;
getURL(theSelectedNodeURL, "_blank");
}
}
};
myTree.addEventListener("change", myTreeListener);

stop();

---------------------------------

!!!
Note the weird way of accessing the child nodes.
The getTreeNodeAt() function returns a collection to you can access the subnodes by using getTreeNodeAt().getTreeNodeAt(); and so on.

The node structure is 0-based so the first child index is 0.

This would target a tree who's instance name is "myTree"

The XML would look like this:

<node label=" Flash">
<node label="Spanish">
<node label=" Dario Quiroga" url="http://www.darioquiroga.com.ar/blogs/" isLink="true"/>
<node label=" Carlos Rovira" url="http://www.carlosrovira.com" isLink="true"/>
</node>
<node label="French">
<node label=" Carlos Rovira" url="http://www.carlosrovira.com">
<node label=" Dario Quiroga" url="http://www.darioquiroga.com.ar/blogs/" isLink="true"/>
</node>
<node label=" After-hours" url="http://www.e-tonilopez.com/after-hours/" isLink="true"/>
</node>
</node>

Thanks to the www.cybernautic.com.au brothers for the help on this one.
Fowie said on Jan 31, 2005 at 8:53 AM :
Can anyone explain why, in MX Professional 2004 v 7.2 when I type tree.setIsOpen( I get the syntax helper and it gives me FOUR options, node, open, animate, fireEvent ? I want to use fireEvent, but according to this site, there's only three options, and fireEvent isn't one of them?
jepo said on Feb 8, 2005 at 6:09 PM :
Thanks. I have checked the Tree class file, and it appears to be an option. I will file a bug accordingly. I will try to blog an example soon on www.markme.com/dehaan.

Regards,
Jen.
ChrisB5733 said on Feb 14, 2005 at 9:13 AM :
Nevermind... figured it out thanks to Fowie's comment:

setIsOpen(node,true,true,"nodeOpen")
jenschr said on Oct 11, 2005 at 3:29 AM :
Here's the requested recursive function that will open nodes where the attribute isOpen set to "true".

function recurseAndOpen(x:XML,tree:Object){
if(!_global.xHowManyNodes){ _global.xHowManyNodes = 0; }
for(var each in x.childNodes){
if(x.childNodes[each].attributes.isOpen == "true"){
var t = tree.getDisplayIndex(x.childNodes[each]);
tree.setIsOpen(tree.getNodeDisplayedAt(t), true,false,false);
}
_global.xHowManyNodes++;
// then recurse for all subnodes
if(x.childNodes[each] != undefined){
recurseAndOpen(x.childNodes[each],tree)+1;
}
}
}

// Send in the XML and the tree-object like this
recurseAndOpen(this.firstChild, main.rootObject.tree);

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00002901.html