PDA

View Full Version : combobox problem


YounqCass
10-24-2007, 06:53 PM
I have a combo box which is populated by an xml file. now i would like that when a label is selected that I can bring up some different information.
I have most of the code written however when i trace the label that is selected i get "Undefined" in my output. Any help would be great. Thank you

var myXML:XML = new XML();
var RootNode:XMLNode;

myXML.ignoreWhite = true;
myXML.onLoad = myfunction;
myXML.load("artists.xml");
stop();

var CBOListener:Object = new Object();
CBOListener.change = loadSubmission;
artist_cb.addEventListener("change",CBOListener);

function myfunction(success:Boolean):Void{
if (success){
RootNode = myXML.firstChild;
loadCombo();
}
else{
trace("Error loading XML File");
}
}

function loadCombo():Void{
var artistName:String;
artist_cb.addItem("--Select Artist--");
for (var i:Number=0; i < RootNode.childNodes.length; i++){
artistName = RootNode.childNodes[i].childNodes[0].childNodes;
artist_cb.addItem(artistName);
trace(artistName);
}
}

function loadSubmission(evtObj:Object):Void{
trace(evtObj.target.selectedItem.label);
}

tg
10-24-2007, 09:11 PM
welcome to as[org]
try:

artist_cb.addItem({label:artistName});


dont know if that will do it for you, but worth a shot.

YounqCass
10-25-2007, 03:15 PM
Thanks tg
For some reason when i trace a nodes' text value id get undefined from Output. But when i trace a Attribute node then it works fine. Which brings me to another question as to how can i populate a combo box with childnodes and actually select the childnode?

tg
10-25-2007, 04:23 PM
hrm... it has been over a year since i have had to deal with much xml.... i might not be the best choice for help on this one.

best way would likely be to push your xml values into an array of some sort, then use that array as your dataprovider for your combobox. might try searching thru the forums for more info.