XML and V2 Tree Example 2: Open/Close All.

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

Add the following code to the first frame

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;
}

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

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

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)

Leave a Reply