# AS3 XML driven menu

**URL:** <https://forum.kirupa.com/t/as3-xml-driven-menu/250424>\
**Category:** flash\
**Created:** [January 29, 2008, 2:21pm UTC](https://forum.kirupa.com/t/as3-xml-driven-menu/250424 "2008-01-29T14:21:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yzx5000](https://avatars.discourse-cdn.com/v4/letter/y/59ef9b/32.png) [@yzx5000](https://forum.kirupa.com/u/yzx5000)\
**Post date:** [January 29, 2008, 2:21pm UTC](https://forum.kirupa.com/t/as3-xml-driven-menu/250424/1 "2008-01-29T14:21:04Z")

</div>

Hi everyone,

[LEFT]I’ve just recently read the tutorial [Using XML in Flash CS3/AS3](http://www.kirupa.com/forum/../developer/flashcs3/using_xml_as3_pg1.htm)  
And I started building a little menu that is supposed to attach movieclips according to the structure of the XML, like a directory structure in windows explorer.

The code looks like this :d: :

```auto

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
 
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("domains.xml")); 

function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    ParseDom(xmlData);
}
 

function ParseDom(domainInput:XML):void {
    
         
    var yPos:int;
    for each (var domainInfo:XML in domainInput.domain.title) {
        var item:MovieClip = new Item();
        if (domainInfo.name() == "title") {
            item.domain_text.text = domainInfo;
        }
        item.y = yPos;
        yPos = item.height;
        item.buttonMode = true;
        item.mouseEnabled = false;
        var container:Sprite=new Sprite();
        container.y = yPos;
        for each (var subdomainInfo:XML in domainInput.domain.subdomain.title) {
            var subitem:MovieClip = new subItem();
            if (subdomainInfo.name() == "title") {
                subitem.subdomain_text.text = subdomainInfo;
            }
            subitem.y = yPos;
            yPos = container.height;
                        
            for each (var publisherInfo:XML in domainInput.domain.subdomain.publisher.title) {
                var publisher:MovieClip = new publisherItem();
                if (publisherInfo.name() == "title") {
                    publisher.publisher_text.text = publisherInfo;
                }
                publisher.buttonMode = true;
                publisher.y = yPos;
                subitem.addChild(publisher);
                trace("subsubbutton");
            }
            container.addChild(subitem);
            trace("subbutton");
        }
        item.addChild(container);
        addChild(item);
        trace("button");        
    }
}

```

[/LEFT]
