« Wheeeeeeeeeeeeeeeeeee | ^ Main | The New Adobe.com »


Flex 2: US States ComboBox Component

It is so easy to create a component in Flex 2. I never got into doing them in Flash because it seemed like so much extra work that wasn’t worth it; always interested…just never took the plunge. Well, Flex 2 changes all of that. Creating a component is as simple as creating a new MXML doc, giving it a base class (in this case mx:ComboBox), and doing whatever it is you want to do. :-)

I needed a combobox that listed all of the states. I basically took the states from another Flash combobox with the same data. It isn’t much but could save you some typing time.


<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
	<mx:dataProvider>
		<mx:String>AL</mx:String>
		<mx:String>AK</mx:String>
		<mx:String>AS</mx:String>
		<mx:String>AZ</mx:String>
		<mx:String>AR</mx:String>
		<mx:String>CA</mx:String>
		<mx:String>CO</mx:String>
		<mx:String>CT</mx:String>
		<mx:String>DE</mx:String>
		<mx:String>DC</mx:String>
		<mx:String>FL</mx:String>
		<mx:String>GA</mx:String>
		<mx:String>GU</mx:String>
		<mx:String>HI</mx:String>
		<mx:String>ID</mx:String>
		<mx:String>IL</mx:String>
		<mx:String>IN</mx:String>
		<mx:String>IA</mx:String>
		<mx:String>KS</mx:String>
		<mx:String>KY</mx:String>
		<mx:String>LA</mx:String>
		<mx:String>ME</mx:String>
		<mx:String>MH</mx:String>
		<mx:String>MD</mx:String>
		<mx:String>MA</mx:String>
		<mx:String>MI</mx:String>
		<mx:String>MN</mx:String>
		<mx:String>MS</mx:String>
		<mx:String>MO</mx:String>
		<mx:String>MT</mx:String>
		<mx:String>NE</mx:String>
		<mx:String>NV</mx:String>
		<mx:String>NH</mx:String>
		<mx:String>NJ</mx:String>
		<mx:String>NC</mx:String>
		<mx:String>ND</mx:String>
		<mx:String>OH</mx:String>
		<mx:String>OK</mx:String>
		<mx:String>OR</mx:String>
		<mx:String>RI</mx:String>
		<mx:String>SC</mx:String>
		<mx:String>SD</mx:String>
		<mx:String>TN</mx:String>
		<mx:String>TX</mx:String>
		<mx:String>UT</mx:String>
		<mx:String>VT</mx:String>
		<mx:String>VI</mx:String>
		<mx:String>VA</mx:String>
		<mx:String>WA</mx:String>
		<mx:String>WV</mx:String>
		<mx:String>WI</mx:String>
		<mx:String>WY</mx:String>
	</mx:dataProvider>
</mx:ComboBox>

One thing to note is calling (if myCombo was your id) myCombo.selectedItem returns the value. No need to read the lable or data field here.

I hope this helps someone.

Posted by John C. Bland II on April 28, 2006 2:43 AM |

TrackBack

TrackBack URL for this entry:
http://mt.katapultmedia.com/mt-tb.cgi/119

Post a comment