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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding a value in XML file 1

Status
Not open for further replies.

CGann

Programmer
Jan 23, 2004
31
US
I've built a flash app that loads an xml file, populates a dropdown, and displays a result based on the user's selection.

I'd like to be able to make selections based on a url variable. i.e Some hardcoded links below the dropdown.

I'm passing the url variable to the flash file just fine, and, for the sake of debugging, I'm displaying the value in a temporary textbox.

Now what do I do? How do I extract the xml data using a url variable? Can anyone point me in the right direction?

Here's an examle of the xml file:
<tz_data>
<Location>
<LocationID>US-SA</LocationID>
<Country>Alabama</Country>
<Region>South Atlantic</Region>
<Landmarks>
<City>Buckstown</City>
</Landmarks>
<StdAbbrev>EST</StdAbbrev>
<DstAbbrev>EDT</DstAbbrev>
</Location>
</tz_data>

I'd like to extract the data for the node by passing a url variable like: "locations.html?LocationID=US-SA"

Again, the url variable is being passed just fine. I'm just not sure where to go from here. Thoughts?

Painted myself in a corner.

CG
 
This is depends on whether you are using AS2 or AS3, but in AS3 you can do:

[tt]trace(xml.Location.(LocationID == LocationID).Landmarks.City);[/tt]

Output:
Buckstown

How cool is that!

Kenneth Kawamoto
 
That IS cool!

I'm using AS2 because it has to be playable in FlashPlayer 6.

Here's a bit of a followup question/scenario: Before I got your reply, I built a function "findLocation()" that checks to see if the variable "LocationID" is defined (i.e. it's length is greater or equal to 2(which happens to be the shortest allowable ID in the file). It then loops through the xml file and stops when it finds it.

Now, I've already got a changeHandler set for the dropdown. Can I pass the index of LocationID's node to the dropdown's changeHandler, or do I need to script a seperate function to handle passed url variables?

Off Topic: I want to say thanks Ken. I've learned a lot about flash in the past 2 months, primarily from reading the many replys from you and OldNewbie. That you, and the others, take the time to people like me learn the ropes says a lot about the types of people that you are.

Thank you.

CG
 
Couldn't understand exactly what you are trying to do...
But what I usually do in AS2 is to create an Array of Objects from XML - something like:

[tt]var locations:Array = [{LocationID:"US-SA", Country:"Alabama", Region:"South Atlantic", ...}, {another Object}, ...][/tt]

So that retrieving a data is easy:

[tt]trace(locations[0].LocationID);[/tt]
US-SA

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top