Lets enhance the last example by adding two buttons to open and close all tree nodes

Add the following code to the first frame

[cc lang=”actionscript3″]function openOrCloseAll (x, open:Boolean) { if (tree.getIsBranch (x)) { tree.setIsOpen (x, open, false, false); } for (var i = 0; i < x.childNodes.length; i++) { if (x.childNodes[i].nodeType == 1) { arguments.callee (x.childNodes[i], open); } } return x; } [/cc]

Add two push button (v2) components to the document and label them “Open All” and “Close All”

write the following code for “Open All” button

?Add two push button (v2) components to the document and label them “Open All” and “Close All”

write the following code for “Open All” button

[cc lang=”actionscript3″]on (click) { _parent.openOrCloseAll (_parent.sample_xml.firstChild, true); }

[/cc]


write the following code for “Close All” button

on (click) {
        _parent.openOrCloseAll (_parent.sample_xml.firstChild, false);
}

It is very important to pass the firstChild instead of the xml itself for “Close All” otherwise tree root node itself will be closed (there will be no visible tree nodes)