[image]

ActionScript State Abbreviations Combo Box (U.S. 50 states)

Tutorial: Create a “state” drop-down (combo box) which displays all 50 states in ActionScript 3.0. The states are given in the example.

I recently worked on a project where I had to come up with a combo box component which contained state abbreviations (United States that is). It would be great to have this code aleady made.

In the spirit of making your life easier, listed below is code for use in ActionScript, which you can then assign to your combo box. You would use it in the following manner:

1) Create a comboBox instance on stage (drag from the component library)

2) Give that comboBox and instance name. I call mine “dropDown”

3) Create a reference to that comboBox, like so:

var dropDown:ComboBox = _root.dropDown;

4) Create an array which holds the state data (given to you below):

var stateData = new Array ( {data: ‘AK’, label: ‘Alaska’}, {data: ‘AL’, label: ‘Alabama’}, {data: ‘AR’, label: ‘Arkansas’}, {data: ‘AZ’, label: ‘Arizona’}, {data: ‘CA’, label: ‘California’}, {data: ‘CO’, label: ‘Colorado’}, {data: ‘CT’, label: ‘Connecticut’}, {data: ‘DE’, label: ‘Delaware’}, {data: ‘DC’, label: ‘District of Columbia’}, {data: ‘FL’, label: ‘Florida’}, {data: ‘GA’, label: ‘Georgia’}, {data: ‘HI’, label: ‘Hawaii’}, {data: ‘IA’, label: ‘Iowa’}, {data: ‘ID’, label: ‘Idaho’}, {data: ‘IL’, label: ‘Illinois’}, {data: ‘IN’, label: ‘Indiana’}, {data: ‘KS’, label: ‘Kansas’}, {data: ‘KY’, label: ‘Kentucky’}, {data: ‘LA’, label: ‘Louisiana’}, {data: ‘MA’, label: ‘Massachusetts’}, {data: ‘MD’, label: ‘Maryland’}, {data: ‘ME’, label: ‘Maine’}, {data: ‘MI’, label: ‘Michigan’}, {data: ‘MN’, label: ‘Minnesota’}, {data: ‘MS’, label: ‘Mississippi’}, {data: ‘MO’, label: ‘Missouri’}, {data: ‘MT’, label: ‘Montana’}, {data: ‘NC’, label: ‘North Carolina’}, {data: ‘ND’, label: ‘North Dakota’}, {data: ‘NE’, label: ‘Nebraska’}, {data: ‘NH’, label: ‘New Hampshire’}, {data: ‘NJ’, label: ‘New Jersey’}, {data: ‘NM’, label: ‘New Mexico’}, {data: ‘NV’, label: ‘Nevada’}, {data: ‘NY’, label: ‘New York’}, {data: ‘OH’, label: ‘Ohio’}, {data: ‘OK’, label: ‘Oklahoma’}, {data: ‘OR’, label: ‘Oregon’}, {data: ‘PA’, label: ‘Pennsylvania’}, {data: ‘RI’, label: ‘Rhode Island’}, {data: ‘SC’, label: ‘South Carolina’}, {data: ‘SD’, label: ‘South Dakota’}, {data: ‘TN’, label: ‘Tennessee’}, {data: ‘TX’, label: ‘Texas’}, {data: ‘UT’, label: ‘Utah’}, {data: ‘VA’, label: ‘Virginia’}, {data: ‘VT’, label: ‘Vermont’}, {data: ‘WA’, label: ‘Washington’}, {data: ‘WI’, label: ‘Wisconsin’}, {data: ‘WV’, label: ‘West Virginia’}, {data: ‘WY’, label: ‘Wyoming’} );

5) Set the data provider of the combo box to be the variable that contains the array:

dropDown.dataProvider = new DataProvider(stateData);

And you’re good!

Tags: ActionScript 3.0, components, Tutorial

Jay Harley is a technology consultant and entrepreneur specializing in creating business productivity software. From 2002-2008, Jay worked as an MFA New Media instructor at the Academy of Art University in San Francisco, where he developed several courses in web application design and scripting, and enjoyed daily interaction with design students, offering guidance, support, and camaraderie as a media professional. Jay is now focused on providing Web 3.0 solutions to businesses in the form of collaboration and presentation software, by utilizing the power of the "Web as a Platform."



1 Comment so far

Hi on June 19th, 2008

[Bindable] public var stateData:ArrayCollection = new ArrayCollection(
[{data: "AK", label: "Alaska"}, {data: "AL", label: "Alabama"},
{data: "AR", label: "Arkansas"}, {data: "AZ", label: "Arizona"},
{data: "CA", label: "California"}, {data: "CO", label: "Colorado"},
{data: "CT", label: "Connecticut"}, {data: "DE", label: "Delaware"},
{data: "DC", label: "District of Columbia"}, {data: "FL", label: "Florida"},
{data: "GA", label: "Georgia"}, {data: "HI", label: "Hawaii"},
{data: "IA", label: "Iowa"}, {data: "ID", label: "Idaho"},
{data: "IL", label: "Illinois"}, {data: "IN", label: "Indiana"},
{data: "KS", label: "Kansas"}, {data: "KY", label: "Kentucky"},
{data: "LA", label: "Louisiana"}, {data: "MA", label: "Massachusetts"},
{data: "MD", label: "Maryland"}, {data: "ME", label: "Maine"},
{data: "MI", label: "Michigan"}, {data: "MN", label: "Minnesota"},
{data: "MS", label: "Mississippi"}, {data: "MO", label: "Missouri"},
{data: "MT", label: "Montana"}, {data: "NC", label: "North Carolina"},
{data: "ND", label: "North Dakota"}, {data: "NE", label: "Nebraska"},
{data: "NH", label: "New Hampshire"}, {data: "NJ", label: "New Jersey"},
{data: "NM", label: "New Mexico"}, {data: "NV", label: "Nevada"},
{data: "NY", label: "New York"}, {data: "OH", label: "Ohio"},
{data: "OK", label: "Oklahoma"}, {data: "OR", label: "Oregon"},
{data: "PA", label: "Pennsylvania"}, {data: "RI", label: "Rhode Island"},
{data: "SC", label: "South Carolina"}, {data: "SD", label: "South Dakota"},
{data: "TN", label: "Tennessee"}, {data: "TX", label: "Texas"},
{data: "UT", label: "Utah"}, {data: "VA", label: "Virginia"},
{data: "VT", label: "Vermont"}, {data: "WA", label: "Washington"},
{data: "WI", label: "Wisconsin"}, {data: "WV", label: "West Virginia"},
{data: "WY", label: "Wyoming"}]);

Posting your comment.

Leave a Reply

You must be logged in to post a comment.


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser
Mobilytics