# XML drop down menu that populates a list menu

**URL:** https://forum.kirupa.com/t/xml-drop-down-menu-that-populates-a-list-menu/268350
**Category:** flash
**Created:** [August 12, 2008, 9:51pm UTC](https://forum.kirupa.com/t/xml-drop-down-menu-that-populates-a-list-menu/268350 "2008-08-12T21:51:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bborntrager](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@bborntrager](https://forum.kirupa.com/u/bborntrager)
#### Post date: [August 12, 2008, 9:51pm UTC](https://forum.kirupa.com/t/xml-drop-down-menu-that-populates-a-list-menu/268350/1 "2008-08-12T21:51:58Z")

</div>

I was wondering if anyone could help me out. I’ve taken a few tutorials and from different sites and customized them, but I’m still new to AS 3 and a bit scared of XML, arrays and loops. if anyone can tell me what im doing wrong, that would be excellent. I’ve attached the xml file as well.

thanks in advance.  
-b

ps. if someone has a better way of doing this, i’m open to suggestions. thanks.

//Imports needed for animation  
import fl.transitions.Tween;  
import fl.transitions.easing._;  
import caurina.transitions._;  
import fl.data.DataProvider;

//Array used for the tween so they won’t get garbage collected  
var tweensArray:Array = new Array();  
//Used later when we animate the buttons  
var buttonTween:Tween;

var yOffset:Number;  
var yMin:Number = 0;  
var yMax:Number = scrollbox.sb.track.height - scrollbox.sb.thumb.height;

var leagueXML:XML = new XML();  
var loader:URLLoader = new URLLoader();  
var request:URLRequest= new URLRequest(“league.xml”);

loader.addEventListener(Event.COMPLETE,loaderOnComplete);  
loader.load (request);

function loaderOnComplete(event:Event):void{  
leagueXML = new XML(event.target.data);

```
// Define an array
var league:Array = new Array({label:"Select a Conference",data:""});

// Loop through each video in XML
for each (var conf:XML in leagueXML.conf){
    league.push({label:conf.name.toString(),data:conf.team.toString()});
}

// Add array to Combo Box
confCB.dataProvider = new DataProvider(league);

```

}

confCB.addEventListener(Event.CHANGE, changeHandler);

// Tell Flash what to do when an item in the ComboBox is clicked

function changeHandler(event:Event):void {  
if(ComboBox(event.target).selectedItem.data != “”)  
{  
//trace(ComboBox(event.target).selectedItem.data);  
createMenu();  
//trace(leagueXML.league.conf.team.toString());

function createMenu ():void {  
//This will be used to represent a menu item  
var menuItem:MenuItem;  
//Counter  
var i:uint = 0;

```
//Loop through the links found in the XML file
for each (var team:XML in leagueXML.league.conf) {
    
    menuItem = new MenuItem();

    //Insert the menu text (link.@name reads the link's "name" attribute)
    menuItem.menuLabel.text = team.name;

    //If the text is longer than the textfield, autosize so that the text is 
    //treated as left-justified text
    menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;

    //Insert the menu button to stage
    menuItem.x = 0;
    menuItem.y = 0 + i*31;

    //Make the button look like a button (hand cursor)
    menuItem.buttonMode = true;
    menuItem.mouseChildren = false;

    //Add event handlers (used for animating the buttons)
    menuItem.addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);
    menuItem.addEventListener (MouseEvent.MOUSE_OUT, mouseOutHandler);
    menuItem.addEventListener (MouseEvent.CLICK, mouseClick);

    //menu_container.holder_mc.addChild (menuItem);
    scrollbox.content.holder_mc.addChild (menuItem);
    //Increment the menu button counter, so we know how many buttons there are
    i++;
}
if (i &lt; 12) {
    scrollbox.sb.visible=false;
    scrollbox.x = 8.5;
}

```

}
