Developer Network Home  Help 

YDN Flash Developer Center Astra Flash Components Using AutoComplete
Flash Developer Center

ASTRA AutoComplete

AutoComplete is a specialized text entry field that provides a list of suggestions from a supplied data set based on the characters entered by the user.

Using AutoComplete in Flash CS3

In Getting Started, we created a simple AutoComplete example. Let's go beyond that by creating a real-world example using AutoComplete to help the user select an airport by airport code or city.

Please be sure that the AutoComplete component appears in your library, or your project will not run correctly. First let's import the stuff we'll need.

Next, let's set up some data. Here we'll use an XML list of the top 30 airports around the world. Instead of a simple array, we'll use XML to allow for codes as well as cities and other info.

The following code will instantiate the AutoComplete instance, place it on the stage, and modify a few properties.

In this case we've set the labelField to "name" to display that field in the list that will pop up (and when an item is selected, it will show that field as text in the text field). If you'd prefer to show, for instance, the airport codes, choose "code" as the labelField. Here we've also set the autoFillEnabled property to true. This will cause the text field to automatically complete with the most obvious entry (and the user can hit backspace to ignore it).

Next we'll create our own filter function. The default filter function searches for matches based on the labelField, so that would only show the "San Francisco Int'l Airport" if "San Fr.." was typed in. If a savvy user who's memorized all the airport codes tried to enter "SFO" it wouldn't match. That's no fun, so we'll fix that by setting a custom filter function, which will display matches for airport codes, cities, or the names of airports (think "New York City" and "John F. Kennedy Airport").

Now it should work as expected, and turn out to be a pretty useful component. Here's the full example you can copy and paste. We love to make components for travel applications, and it shows.

Screen capture of AutoComplete

To see a live example, please install Adobe Flash Player version 9 or higher.

Download the FLA file.

For additional information, please take a look at the Examples section for functional demonstrations and the ActionScript 3.0 Class Reference for full details on every property, method, and style available to the AutoComplete component.