-
[F8] Array from an XML data
Hi,
i have a problem. I would like to retrive xml data from an external file. An than i would collect data from that xml to be compared with some id buttons.
ex. IF (xml output atributte) == (id of button), than dissplay button red, else dissplay blue.
I have no problems till here. This is the array and its conntent.
var dataValues = new Array();
dataValues[0] = "100";
dataValues[1] = "131";
if i do it manualy, like you see above, it all works fine. The buttons respond to it just fine and have the correct color. But if i try to implement it to a load from the xml file all the buttons stay blue.
I dont know how to set an array in this:
function loadXML(loaded) {
if (loaded) {
dataValues[42] = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
// EVEN IF I TRY dataValues[1] = "200" or something. It just doesent work in that function
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("buttons.xml");
Please help. Ive been trying all day and no success.
-
FK'n_dog
it always helps if you show the xml format.
can you not use an attribute element and populate the array from it ?
Code:
_xml = new XML();
_xml.ignoreWhite = true;
_xml.load("number.xml");
dataArray = [];
_xml.onLoad = function(){
aNode = this.firstChild.childNodes;
len = aNode.length;
for(var n=0; n!=len; n++){
dataArray[n] = aNode[n].attributes.num;
}
tracer();
};
function tracer(){
for(var n=0; n!=len; n++){
trace("dataArray["+n+"] = "+dataArray[n]);
}
};
/*--in xml file--
<?xml version="1.0" encoding="UTF-8"?>
<anode>
<node num="5" />
<node num="10" />
</anode>
*/
-
Great,
it almost works perfectly. Just one problem, how could i trace it or call it outside the onLoad function. It just traces undefined.
Thanks,
-
FK'n_dog
trace it or call it outside the onLoad function
that is what the tracer function is doing.
the onLoad function fires when the data has completed loading,
so you could use it to move the timeline to the next frame, where
all variables will be available for tracing
-
a little fix:
PHP Code:
_xml.onLoad = function(success){
if (success){
aNode = this.firstChild.childNodes;
len = aNode.length;
for(var n=0; n!=len; n++){
dataArray[n] = aNode[n].attributes.num;
}
tracer();
}else{
trace("error loading XML");
}
};
othewise it will run the loop as well if th file is not present - and that will propaly result into a crash
-
FK'n_dog
ta render.. i rarely use the boolean if/else for error catching for test files,
(just too damn lazy to do all that extra typing, i s'pose )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|