PDA

View Full Version : help with XML scripting


Navarone
08-31-2006, 05:58 PM
I have an XML file that I want to have 2 libraries: tables and chairs. And I am having a little trouble getting my combo box to populate correctly with the different libraries. Whats happening is that the tables library is showing up numerous time in the combo box and the chairs library isn't showing up at all.This is my XML file

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<libraries name="tables">
<item source="end_table">End Table</item>
<item source="rd_table">Round Table</item>
</libraries>
<libraries name="chairs">
<item source="chair">Recliner</item>
<item source="sofa">Leather Sofa</item>
</libraries>


and my flash script

var myXML:XML = new XML();
myXML.ignoreWhite = true;
libraryList_ar = new Array();
combo_list.dataProvider = libraryList_ar;
myXML.onLoad = function(success) {
if (success) {
var rootList = this.firstChild
//trace(rootList)
var items = rootList.attributes.name
trace(items)
for (var i = 0; i<items.length; i++) {
libraryList_ar[i] = items
}

}
};
myXML.load("myXML.xml");
}

Navarone
09-01-2006, 11:39 AM
I haven't had any luck since yesterday and it would seem it's to tuff for some of you.:rolleyes:

I'll keep pluging away and maybe I'll hit upon the answer.:)

Navarone
09-01-2006, 04:06 PM
Ok I figured this much out
Here is my revised code:

var myXML:XML = new XML();
myXML.ignoreWhite = true;
libraryList_ar = new Array();
//combo_list.dataProvider= ["Library", "Tables", "Chairs", "Sofas", "Hutches"];
combo_list.dataProvider = libraryList_ar;
myXML.onLoad = function(success) {
if (success) {
//trace(this);
var libraries:XMLNode = this.firstChild;
var libItems = libraries.childNodes.length;
trace(libItems);
for (var i = 0; i<libItems; i++) {
libraryList_ar[i] = libraries.childNodes[i].attributes.name;
trace(libraryList_ar[i]);
}
}
};
myXML.load("myXML.xml");
//
combo_list.change = function(eventObj) {
trace("Value changed to "+eventObj.target.value);
};
combo_list.addEventListener("change", combo_list);



the XML file looks like this:


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<furniture>
<tables name="Tables">
<item title="End Table">end_table</item>
<item title="Round Table">rd_table</item>
</tables>
<chairs name="Chairs">
<item title="Recliner">chair</item>
</chairs>
<sofas name="Sofas">
<item title="Leather Sofa">sofa</item>
</sofas>
<hutches name="Hutches">
<item title="Double Hutch">hutch</item>
</hutches>
</furniture>

Navarone
09-01-2006, 07:05 PM
ok, I have been humbled once again. I want to find out how many items are in the libraries.

I know there are 4 libraries, Tables, Chairs, Sofas and Hutches. But how do I get a count of the items in each of these? I have changed a few things in my code to make more sense the XML hasn't changed.


var myXML:XML = new XML();
myXML.ignoreWhite = true;
libraryList_ar = new Array();
libraryItems_ar = new Array();
//combo_list.dataProvider= ["Library", "Tables", "Chairs", "Sofas", "Hutches"];
combo_list.dataProvider = libraryList_ar;
myXML.onLoad = function(success) {
if (success) {
//trace(this);
//
var libraries = this.firstChild;
trace(firsChild.nodeValue)
var libCount = libraries.childNodes.length;
trace(libCount);
var libItems = libraries.childNodes.childNodes.length;
trace(libItems);
for (var i = 0; i<libCount; i++) {
//libraryList_ar[i] = libraries.childNodes[i].childNodes[0].firstChild.nodeValue;
libraryList_ar[i] = libraries.childNodes[i].attributes.name;
}
}
};
myXML.load("myXML.xml");
//
combo_list.change = function(eventObj) {
//trace("Value changed to "+eventObj.target.value);
};
combo_list.addEventListener("change", combo_list);