PDA

View Full Version : setting variables dynamically in a for loop.


DaMacGeek
03-28-2003, 08:03 PM
hello all

this is what I have now which works

for (x=0; x <= xmlDoc_xml.childNodes[2].childNodes[1].childNodes.length; x++) {

v_Team0Name = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];
v_Team0Wins = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[1];
v_Team0Loses = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[2];
v_Team0Pts = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[3];

v_Team1Name = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];
v_Team1Wins = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[1];
v_Team1Loses = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[2];
v_Team1Pts = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[3];

v_Team2Name = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];
v_Team2Wins = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[1];
v_Team2Loses = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[2];
v_Team2Pts = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[3];
}

what I would like to know is how can I access my variables dynamically in the for loop
this is what I've been trying


this["v_Team"+x+"Name"] = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];
level0.Standings:"v_Team" + x + "Name" = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];
"v_Team" + x + "Name" = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];


it's probably something really simple that I'm not seeing....
any thoughts?

thanks
JOrdan

Jesse
03-30-2003, 05:25 AM
The first line, which reads:
this["v_Team"+x+"Name"] = xmlDoc_xml.childNodes[0].childNodes[0].childNodes[x+1].childNodes[0];
is right and should work... The others are wrong and should be avoided...
If you're still having troubles, try using _root instead of "this" as the parent timeline may be the issue. If the variables work when using _root[...] then try _parent in place of this. It will depend on the structure of your movie.

DaMacGeek
03-30-2003, 02:48 PM
thanks _parent worked for me
thanks for the reply!