I have the following XML variable:
public var Country:XML=new XML(
<countries>
<country code="US" iso="840" label="United States" />
<country code="CA" iso="124" label="Canada" />
<country code="GB" iso="826" label="United Kingdom" />
...
</countries>);
How would I loop through the list to find the index number corresponding to the value stored in String variable myCountry? For example, if
var myCountry:String = "Canada";
How to create a loop that returns an index value of 1, meaning Canada is the 2nd element in the XML list?
Or, maybe looping isn’t necessary if the index value of 1 can be returned some other way. I tried:
var desiredIndex:int = Country.country.(@label==myCountry)
but it gives the error No such variable: @label.
Something like this should do what you want:
(the
Countryvariable should be namedcountriesor something similar… conventionally capitalised names are used for classes only)I hope this helps