PDA

Click to See Complete Forum and Search --> : xml function problem - please help!



lantern
05-17-2001, 12:59 AM
hello

i have written a function that goes through my xml document (which is pretty simple - just a root node "topmost", with a "link" node, and in each "link" node are two children nodes, "url" and "name") and puts each name and link into their own array "link_name" and "link_url".

trouble is, i cant access either of the arrays outside of the function. i can get a textfield to display the last url in the link_url array, but if i try to display any of the previous ones it wont. on the other hand if i try to trace them i can see them all being shown.

however if i do a trace outside of the function i cant see anyof them.

heres the function:

function convertXML() {

mainTag = new XML();
elementTag = new XML();
linkList = new Array();
elementList = new Array();

mainTag = this.firstChild.nextSibling;

if (mainTag.nodeName.toLowerCase() == "topmost") {
linkList = mainTag.childNodes;

for (i=0;i<=linkList.length;i++){
link_url = new Array();
link_name = new Array();
if(linkList["i"].nodeName.toLowerCase() == "link"){
elementList =linkList["i"].childNodes;
for(j=0;j<=elementList.length;j++){
elementTag = elementList[j];
elementType = elementTag.nodeName.toLowerCase();
if (elementType == "name"){
link_name["i"] = elementTag.firstChild.nodeValue;

}
else {
if (elementType=="url") {
link_url["i"] = elementTag.firstChild.nodeValue;

}
}
}
}
}
}
}


any ideas?

Hythian
05-17-2001, 01:14 PM
You can't access the array's outside of the function because they are "local" to the function and only exist within the function. You need to declare them outside of the function for them to be used outside of the function.

Local:
myfunction () {
...
link_url = new Array();
...
}

Global:
link_url = new Array();
myfunction () {
...
}


Since they are an array, a text field will only display the value that the array was left on if you point it directly to a text field. if you do an array.join() you will get a comma delineated list of array values.

-Hythian

lantern
05-17-2001, 06:10 PM
thanks!!

so you cant tell a textfield to display particular elements of an array? like _root.movieclip.textfield = link_url[1] ?

if i joined an array how would i then display separate elements?

lantern
05-17-2001, 06:18 PM
grr!

i tried putting the link_url and link_name arrays outside of the function (of course removing the array initialisation within the function) but when i do a trace outside the function i still get no values...