Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Flash ComboBox Component ActionScript 3 Tutorial

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

Please update flash player to view this Flash ActionScript tutorial!

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.