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); }
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); }
Don't see what you're looking for? Try a search.
|