Flash ComboBox Component ActionScript 3 Tutorial
This Flash Component tutorial series show how to use ComboBox with Flash ActionScript 3.
Flash Tutorial Content:
The Flash ComboBox component contains a drop-down list from which the user can select one value. Its functionality is similar to that of the SELECT form element in HTML.
The finished Flash Movie of this tutorial is shown as above. Click on the above Flash Movie and play around.
Flash ActionScript Codes:
//Uncomment the following line if create runtime ComboBox
//import fl.controls.ComboBox;
//Add Items to ComboBox
fruitCombo.prompt = "Please select a fruit";
fruitCombo.addItem( {label: "Apple" } );
fruitCombo.addItem( {label: "Orange" } );
fruitCombo.addItem( {label: "Papaya" } );
fruitCombo.addItem( {label: "Banana" } );
fruitCombo.addItem( {label: "Water Melon" } );
//Add CHANGE event listener to ComboBox
//Whenever the index of Combox CHANGE, function fruitSelect will be called
fruitCombo.addEventListener(Event.CHANGE, fruitSelect);
function fruitSelect(event:Event) {
fruitComboIndex_txt.text = "Selected index of ComboBox is: " + event.target.selectedIndex;
//Display the Label of ComboBox
fruitComboLabel_txt.text = "Selected Label of ComboBox is: " + event.target.value;
if (event.target.selectedIndex == 1) {
//Because the index of prompt of ComboBox is -1
//event.target.selectedIndex = -1;
}
//Add event listener to the Enter button
enter_btn.addEventListener(MouseEvent.CLICK, checkComboIndex);
function checkComboIndex(evt:MouseEvent):void {
fruitComboIndex_txt.text = "Selected index of ComboBox is: " + fruitCombo.selectedIndex;
//Display the Label of ComboBox
fruitComboLabel_txt.text = "Selected Label of ComboBox is: " + fruitCombo.selectedLabel;
//If no menu is selected
//i.e. fruitCombo.selectedLabel == null
//
//You can also use fruitCombo.selectedIndex == -1
/*
if (fruitCombo.selectedIndex == -1) {
*/
if (fruitCombo.selectedLabel == null) {
}
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial shows how to use Flash ComboBox component.