tags:

views:

38

answers:

2

Hi

I have a Flex XML object as follows:

private var _xmlCountries:XML =

<Countries>
  <option value="AF">Afghanistan</option>
  <option value="AL">Albania</option>
  <option value="DZ">Algeria</option>
  <option value="AO">Angola</option>
  <option value="AI">Anguilla</option>
  ........
<Countries>;

This object is ok, and shows up correctly in debug mode. The problem is I have a country name i.e. private var _country:String = "Angola";, and I want to get the corresponding value 'AO' from the XML object. Do you know how to do this?

I have tried loads of Livedocs examples, but cant get it to work!!!

P.S. I am working on a HtpService & WebService driven app to display global weather conditions overlayed on a Google Maps interface. Going to make it available to the Flex community when finished.

+1  A: 

I think this link can help you : http://developer.yahoo.com/flash/articles/e4x-beginner-to-advanced.html

ghalex
A: 

Figured it out:

Converted the XML to an XMLListCollection:

var xmlList:XMLList = _xmlCountries.option;                               
_xmlCountriesListCollection = new XMLListCollection(xmlList);

Looped through the collection, searching for _country = "Angola":

for(var i:int = 0; i < _xmlCountriesListCollection.length; i++)
{
   if(_xmlCountriesListCollection[i] == _country)
   {
      codeISO = _xmlCountriesListCollection[i].@value;
      trace(codeISO);
   }
}

Output: AO

Brian Bishop