Flash CS4 Resources
Use the ComboBox component
A ComboBox component allows a user to make a single selection from a drop-down list. A ComboBox can be static or editable. An editable ComboBox allows a user to enter text directly into the text field at the top of the list. If the drop-down list hits the bottom of the document, it opens up instead of down. The ComboBox is made up of three subcomponents: the BaseButton, TextInput, and List components.
In an editable ComboBox, only the button is the hit area—not the text box. For a static ComboBox, the button and the text box constitute the hit area. The hit area responds by opening or closing the drop-down list.
When the user makes a selection in the list, either with the mouse or through the keyboard, the label of the selection is copied to the text field at the top of the ComboBox.
User interaction with the ComboBox component
You can use a ComboBox component in any form or application that requires a single choice from a list. For example, you could provide a drop-down list of states in a customer address form. You can use an editable ComboBox for more complex scenarios. For example, in an application that provides driving directions, you could use an editable ComboBox, to allow a user to enter her origin and destination addresses. The drop-down list would contain her previously entered addresses.
If the ComboBox is editable, meaning the editable property is true , the following keys remove focus from the text input box and leave the previous value. The exception is the Enter key, which applies the new value first, if the user entered text.
When you add the ComboBox component to an application, you can make it accessible to a screen reader by adding the following lines of ActionScript code:
import fl.accessibility.ComboBoxAccImpl; ComboBoxAccImpl.enableAccessibility();
You enable accessibility for a component only once, regardless of how many instances you have of the component.
ComboBox component parameters
You can set the following parameters in the Property inspector or in the Component inspector for each ComboBox instance: dataProvider , editable , prompt , and rowCount . Each of these parameters has a corresponding ActionScript property of the same name. For information on the possible values for these parameters, see the ComboBox class in the ActionScript 3.0 Language and Components Reference . For information on using the dataProvider parameter, see Use the dataProvider parameter.
Create an application with the ComboBox component
The following procedure describes how to add a ComboBox component to an application while authoring. The ComboBox is editable and if you type Add into the text field, the example adds an item to the drop-down list.
Create a ComboBox using ActionScript
The following example creates a ComboBox with ActionScript and populates it with a list of universities in the San Francisco, California, area. It sets the ComboBox’s width property to accommodate the width of the prompt text and sets the dropdownWidth property to be slightly wider to accommodate the longest university name.
The example creates the list of universities in an Array instance, using the label property to store the school names and the data property to store the URLs of each school’s website. It assigns the Array to the ComboBox by setting its dataProvider property.
When a user selects a university from the list, it triggers an Event. CHANGE event and a call to the changeHandler() function, which loads the data property into a URL request to access the school’s website.
Notice that the last line sets the ComboBox instance’s selectedIndex property to -1 to redisplay the prompt when the list closes. Otherwise, the prompt would be replaced by the name of the school that was selected.
You can implement and run this example in the Flash authoring environment but you will receive warning messages if you attempt to access the university web sites by clicking items in the ComboBox. To access the fully functional ComboBox on the Internet, access the the following location: