Matt LeGrand is an accomplished user experience specialist with a primary focus on Adobe Flex and Air application development. Matt has been working with Flex since 2005 and Adobe Flash since 1999. His interest are in human computer interaction and interactive media research.
Seems like I'm always trying to put my hands on an XML list of states or list of countries for some Flex project or another. I'm posting these here in hopes that I'm not the only one looking for this information. I used to have this xml posted on a server somewhere and I'd just point a service at it, but now I have no idea where I posted it.
I'm also posting both of these lists as ArrayCollections. I've found this method the easiest and most reusable. I just instantiate the class and bind the view to it, for example:
The StatesArrayCollection looks like this:
And instantiate it where ever I need it.
[Bindable]
protected var statesArrayCollection:StatesArrayCollection=new StatesArrayCollection();
I've also added a quick look up on abbreviation:
/** * Given a state abbreviation this method returns the correct index.
*
* @param abbreviation String
* @return int
* @default Sweet Home Alabama
*/
public function getIndexByAbbreviation(abbreviation:String):int
{
for (var i:int=0; i<this.length; i++)
{
if(this.getItemAt(i).abbreviation == abbreviation)
{
return i
}
}
return 0;
}
So a ComboBox might look like:
<mx:ComboBox id="bestStateInTheUnion"
dataProvider="{statesArrayCollection}"
labelField="abbreviation"
selectedIndex="{statesArrayCollection.getIndexByAbbreviation('AL')}"/>
I don't mind the fact that this information is embed in the application. For the most part this information is static. Now it's possible that Texas will decide to secede from the Union. In which case I'll have to update this list and each application I've used it in.
Come on Governor Perry, I don't need those extra hours.
Do you guys find this helpful? Do you have any utility classes like this that you find yourself using for all of your projects? Should I add something like this in a 'util' folder in the FireStarter application? Thanks for any comments!
Sincerely,
Matt
its really cool, you can get professional help at <a href="http://www.abizc.com"> my site </a>
http://concealer.mybrute.com
Check out the cool mini-game
Thanks a lot Matt!!!
Outstanding! Working on a shopping cart and this is just what I needed. Thanks for putting it together.
Perfect. www.doughughes.net rocks.
Cool! Thanks for that. Exactly what I need. Cheers!
Posted By: Alexander Sokolov on May 3, 2009 at 12:00 AM