all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

cb.addItem() HELP!!!



cb.addItem() HELP!!! acornelio
12/14/2005 10:02:44 PM
flash actionscript: Hi,

I am populating a comboBox with XML. I'm assging the Data param to a variable
that is equal to the selectedIndex of a certian combo box. The label param is
assigned to an XML attribute that assigns the label of the comboBox.

I now want to add a third param called file with in my addItem() method that
will be assigned to a file attribute in my XML. I need some help on this!

here is the code in my XML load function:


function xmlArray(file, array, cb) {
data_xml.onLoad = function(success:Boolean) {
if (success) {

//store paths in var's
rootNode = this.firstChild;
dataNodes = rootNode.firstChild.childNodes;

//loop for the length of nodes
for (var i:Number = 0; i<dataNodes.length; i++) {

//for each node in xml
dataNode = dataNodes[i];
array.push({cbName:dataNode.attributes.name});
cb.addItem({data:arrayNum[i], label:dataNode.attributes.name,
file:dataNode.attributes.file});

}
} else {
trace('error reading XML');
}
};
data_xml.load(file);
}
Re: cb.addItem() HELP!!! NSurveyor
12/14/2005 10:38:28 PM
Make the data property be an object with the arrayNum[ i ]and the file name. So
in the following code, you would use: theItem.data.a for the arrayNum[ i ] and
theItem.data.f for the file.

function xmlArray(file, array, cb) {
data_xml.onLoad = function(success:Boolean) {
if (success) {
//store paths in var's
rootNode = this.firstChild;
dataNodes = rootNode.firstChild.childNodes;
//loop for the length of nodes
for (var i = 0; i<dataNodes.length; i++) {
//for each node in xml
dataNode = dataNodes[i];
array.push({cbName:dataNode.attributes.name});
cb.addItem({data:{a:arrayNum[i], f:dataNode.attributes.file},
label:dataNode.attributes.name});
}
} else {
trace('error reading XML');
}
};
data_xml.load(file);
}
Re: cb.addItem() HELP!!! acornelio
12/15/2005 3:28:27 PM
Thanks, worked great!

Re: cb.addItem() HELP!!! NSurveyor
12/15/2005 11:35:48 PM
AddThis Social Bookmark Button