PDA

View Full Version : [AS2] add item to comboBox via XML


Navarone
08-28-2006, 04:37 PM
I am trying to add items in my XML file to a comboBox component called nav_cb. I get 'undefined' in the comboBox. I am not sure I am doing this correctly.

Do I need a data provider? How do I accomplish this?

var myList:XML = new XML();
myList.ignoreWhite = true;
var showText = 0;
myList_ar = new Array();
myList.onLoad = function(success) {
if (success) {
trace("loaded");
var rootList:XMLNode = this.firstChild;
var listLength = rootList.childNodes.length;
for (var i = 0; i<listLength; i++) {
myList_ar[i] = rootList.childNodes[i].childNodes[0].firstChild.nodeValue;
trace(rootList.childNodes[i].childNodes[0].firstChild.nodeValue)
}

showList();
} else {
trace("not loaded");
}
};
myList.load("myList.xml");
//

function showList() {
var nav_items = myList_ar.length;
for (var i = 0; i<nav_items; i++) {
nav_cb.addItem({label:this["nav_items"+i]});
}
}


My XML file looks like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<furniture>
<tables>
<item>End Table</item>
<item>Round Table</item>
</tables>
<chairs>
<item>Chair</item>
<item>Sofa</item>
</chairs>
</furniture>

Slowburn
08-28-2006, 04:48 PM
I think you just add the array as the data provider to the combo box.

But I don't use these components much.

Navarone
08-29-2006, 12:45 AM
For beginers with XML and flash here is great little introduction that might help. Introduction to XML (http://www.kirupa.com/web/xml/index.htm).:)

Navarone
08-29-2006, 02:38 PM
For some reason I can't get my videoList to appear in my combo box.
Can anyone see what I am missing?


var videoList_xml:XML = new XML();
videoList_xml.ignoreWhite = true;
var showText = 0;
videoList_ar = new Array();
videoList_xml.onLoad = function(succes) {
if (succes) {
var rootList:XMLNode = this.firstChild;
var listLength = rootList.childNodes.length;
for (var i = 0; i<listLength; i++) {
videoList_ar[i] = rootList.childNodes[i].childNodes[0].firstChild.nodeValue;
}
showList();
}
};
videoList_xml.load("videoList.xml");
//
function showList() {
var num_videos = videoList_ar.length;
for (var i = 0; i<num_videos; i++) {
var tempVideo = videoList_ar[i];
trace(tempVideo);
nav_cb.dataProvider = ({label:tempVideo});
}
}

finch124
02-04-2011, 02:42 AM
this is cool. but how do i populate this with xml?