ActionScript 2.0 Components Language Reference |
|
|
|
| ComboBox component > Using the ComboBox component > Creating an application with the ComboBox component | |||
The following procedure explains how to add a ComboBox component to an application while authoring. In this example, the combo box presents a list of cities to select from in its pop-up list.
To create an application with the ComboBox component:The combo box can only be resized on the Stage during authoring. Typically, you would only change the width of a combo box to fit its entries.
These are imaginary SWF files that, for example, you could load when a user selects a city from the combo box.
function change(evt){
trace(evt.target.selectedItem.label);
}
comboBox.addEventListener("change", this);
The last line of code adds a change event handler to the ComboBox instance. For more information, see ComboBox.change.
To create a ComboBox component using ActionScript:This adds the component to the library, but doesn't make it visible in the application.
this.createClassObject(mx.controls.ComboBox, "my_cb", 10);
my_cb.addItem({data:1, label:"One"});
my_cb.addItem({data:2, label:"Two"});
This script uses the method UIObject.createClassObject() to create the ComboBox instance, and then uses ComboBox.addItem() to add list items to the ComboBox.
// Create listener object.
var cbListener:Object = new Object();
// Create event handler function.
cbListener.change = function (evt_obj:Object) {
trace("Currently selected item is: " + evt_obj.target.selectedItem.label);
}
// Add event listener.
my_cb.addEventListener("change", cbListener);
|
|
|
|