# Xml menu

**URL:** <https://forum.kirupa.com/t/xml-menu/171324>\
**Category:** Uncategorized\
**Created:** [December 4, 2005, 11:57am UTC](https://forum.kirupa.com/t/xml-menu/171324 "2005-12-04T11:57:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![g5604](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@g5604](https://forum.kirupa.com/u/g5604)\
**Post date:** [December 4, 2005, 11:57am UTC](https://forum.kirupa.com/t/xml-menu/171324/1 "2005-12-04T11:57:50Z")

</div>

hi,

i am trying to use the example in the xml tutorial here on kirupa (classes menu)… works great apart from ii would like to be able to have all the folders closed to start with… any ideas?

[AS]  
// Folder interaction/placement  
function SetAtBottomOfParent(below\_mc){  
if (below\_mc.\_parent.\_height) {  
below\_mc.\_y = below\_mc.\_parent.getBounds(below\_mc.\_parent).yMax;  
}  
}  
function SetBelow(below\_mc, top\_mc){  
if (top\_mc != undefined) {  
below\_mc.\_y = top\_mc.getBounds(top\_mc.\_parent).yMax;  
}  
}  
function ArrangeContents(directory\_mc){  
var item = directory\_mc.firstChild;  
if (item != undefined){  
while (item = item.nextSibling){  
SetBelow(item, item.previousSibling);  
}  
var parent\_container = directory\_mc.\_parent.\_parent;  
if (parent\_container != undefined) ArrangeContents(parent\_container);  
}  
}  
function Fold(){  
if (this.\_parent.directory\_mc.\_visible){  
this.\_parent.directory\_mc.\_visible = false;  
this.\_parent.directory\_mc.\_yscale = 0;  
}else{  
this.\_parent.directory\_mc.\_visible = true;  
this.\_parent.directory\_mc.\_yscale = 100;  
}  
ArrangeContents(this.\_parent.\_parent);  
scrollbar.contentChanged();  
}

// define basic variables for setting up the menu  
var item\_indent = 15;

function GenerateFileListing(directory\_node, target\_mc){  
var directory\_mc = target\_mc.createEmptyMovieClip(“directory\_mc”, 1);  
SetAtBottomOfParent(directory\_mc);  
directory\_mc.\_x += item\_indent;  
directory\_mc.depth = 0;

```
var contents = directory_node.childNodes;

var item_mc, last_item_mc;
for (var i=0; i&lt;contents.length; i++) {

    item_mc = directory_mc.attachMovie("directory_item","item"+directory_mc.depth, directory_mc.depth);
    directory_mc.depth++;
    
    item_mc.name_txt.text = contents*.attributes.name;
    item_mc.icon_mc.gotoAndStop(contents*.attributes.type);
    
    if (last_item_mc == undefined) directory_mc.firstChild = item_mc;
    else item_mc.previousSibling = last_item_mc;
    last_item_mc.nextSibling = item_mc;
    last_item_mc = item_mc;
    
    if (contents*.attributes.type == "directory"){
        item_mc.select_btn.onPress = Fold;
        GenerateFileListing(contents*, item_mc);
    }
    
    ArrangeContents(directory_mc);
}

```

}

// manage XML  
// create new XML object instance, remembering to ignore white space  
var directory\_xml = new XML();  
directory\_xml.ignoreWhite = true;  
// define an onLoad to create our location menu when the XML has successfully loaded.  
directory\_xml.onLoad = function(success){  
if (success){  
GenerateFileListing(this, listing\_mc);  
scrollbar.setTarget(listing\_mc, view\_mc.\_y, view\_mc.\_height);  
}else trace(“Error loading XML file”); // no success? trace error (wont be seen on web)  
}

// load the xml file!  
directory\_xml.load(“mx04\_classes.xml”);

[/AS]
