Home | Contact Us | Store

Flash ComboBox Component ActionScript 3 Tutorial

This Flash Component tutorial series show how to use ComboBox with Flash ActionScript 3.

Flash ActionScript component control tutorial example display here. Your flash player version is too old to see this Flash tutorial example!

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) {

//Display the Index of ComboBox
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) {
output_txt.text = "Yeah.... " + event.target.value + " is my favorite fruit!";} else {output_txt.text = "Hm......"}//Uncomment if you want ComboBox return to the prompt after user select the menu.
//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 {

//Display the Index of ComboBox
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) {
output_txt.text = "Please select a fruit to get start!";}
*/
if (fruitCombo.selectedLabel == null) {
output_txt.text = "The selected Label of the ComboBox is null";}

}

Download Flash Source File:

Flash Source File combobox.fla

Remarks:

This Flash ActionScript tutorial shows how to use Flash ComboBox component.

ActionScript Component Control Tutorial