Hi
Im working on an Actionscript 3 program where i will click through a tree structure of buttons and use the values of the particular set of buttons, to access its corresponding value in an XML file.
As i click each button, I start forming a string.
Click1 = unit1;
Click2 = lesson1;
xmlString = “myXML.”+ Click1 + “.” + Click2;Here is some of the XML.
Code:
<?xml version=“1.0” encoding=“utf-8”?>
<student>
<unit1>
<lesson1>image1.jpg</lesson1>
<lesson2>image2.jpg</lesson2>
<lesson3>image3.jpg</lesson3>
</unit1>
</student>
So in my code im trying to get the value “image1.jpg” out of my XML.
Im doing it by passing it the concatenated String, xmlString.
If i trace xmlString:
trace(xmlString); //myXML.unit1.lesson1
that is the correct path to the value but im trying to get the value “image1.jpg”, not the path to that value.
Now if i trace that path directly:
trace(myXML.unit1.lesson1); //image1.jpg
I get the correct value when tracing the path directly.
So somehow i need to get the compiler to treat my concatenated string, xmlString, as if it was the xml path, like my second trace statement.
Im stumped, any help would be much appreciated
Solved
var click1:String = “unit1”;
var click2:String = “lesson2”;
trace(myXML[click1][click2].toString());
So you’re not concatenating a string to get a reference but just building a direct reference using bracket syntax rather than dot syntax.