Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing XML node as variables 1

Status
Not open for further replies.

Sammybobo

Programmer
Apr 4, 2003
87
US
I am using Flash 8 for a project on which I am getting data from an XML file. I am loading the file via Actionscript. The file looks like this:

<books>
<no>1</no>
<author>Sussy Awe</author>
<ref>Library</ref>
<no>2</no>
<author>Frank Pity</author>
<ref>Attic</ref>
</books>

I am getting a "no" value from another file and want to use the "no" value to convert elements of the node that has a corresponding value to variables. Once I get the variables, I would like to close the XML file. What's the solution, please? Thanks.
 
What method are you using to load your XML file?

Wow JT that almost looked like you knew what you were doing!
 
I am using the Flash Actionscript object XML like this:

getxmldata=new XML();
getxmldata.load("mybooks.xml","");

Did I get you right? Thanks.
 
I think you'll need to alter the schema of your XML file, what you have just now isn't a proper tree structure, try this:

Code:
<books>
 <book>
  <no>1</no>
  <author>Sussy Awe</author>
  <ref>Library</ref>
 </book>
 <book>
  <no>2</no>
  <author>Frank Pity</author>
  <ref>Attic</ref>
 </book>
</books>

From there I'd load the XML file into Flash using the method you've already outlined and drop the data into an array which will give you easy access to the information via ActionScript. Any comparisons you need to do with other data should be relatively straightforward in Flash from that point.

As for closing the XML file you don't have to do anything, it's not like reading a file in PHP (for example) - once the end of the file is reached there is no action necessary on your behalf.
 
Thanks, Wangbar. Your help is appreciated. I have dynamic textfileds in my movie that correspond to the elements of the book node. Now, if I want to load the contents of the node having "2" as the "no" attribute, could you show me the steps to accomplish that? Also, for an equal amount of text, is using a text file faster than using an xml file in Flash 8? Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top