Copy link to clipboard
Copied
Hi guys,
I have another problem with putting, or shall I say, pushing data from xml to an empty array I previously declared.
During the xml_mc.onload, I can see the data, but after that, it becomes undefined.
It seems like I could not find the solution on the net as well. I suspect it is not possible, but I wont give up.
Please help me.
Thanks.
This is the code sample:
var myarray=new Array();
var xml1:XML = new XML();
xml1.ignoreWhite=true;
xml1.onLoad = function(success:Boolean){
if(success){
var nodes = this.firstChild.childNodes;
for (i=0; i<nodes.length; i++){
myarray=nodes.attributes.name;
}
text1.text=myarray[2]; // *******************************to check if the attribute "name" is visible
} else {
trace("Could not load XML");
}
}
xml1.load("icons.xml");
text1.text=myarray[2]; // *******************************I commented the first text to try to view again, and result was UNDEFINED..........
the xml would look like this:
icons.xml
<icons>
<icon name="icon1" />
<icon name="icon2" />
<icon name="icon3" />
<icon name="icon4" />
</icons>
thanks
I don't understand your problem. The array does fill with the data. If you are expecting that second "text1.text = " to show anything but "undefined" it is not going to happen as you have it written. That line of code executes before the onLoad function does (code execution does not wait for files to load). You only want to deal with processing the data after the onLoad function has processed it into the array.
Copy link to clipboard
Copied
I don't understand your problem. The array does fill with the data. If you are expecting that second "text1.text = " to show anything but "undefined" it is not going to happen as you have it written. That line of code executes before the onLoad function does (code execution does not wait for files to load). You only want to deal with processing the data after the onLoad function has processed it into the array.
Copy link to clipboard
Copied
Hi Ned,
Yes...I now get your point. I have not realized before what you just said...
And it is working now.
Thank you always.
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now