View Full Version : [AS3] ComboBox If function

02-26-2012, 09:31 PM
Could you give me a code from how to make a if functions with the selected label of a ComboBox:
E.g.: If ComboBox selected Label is eyes, gotoAndPlay(2) ;
(this is not a real format function and it doesn't work)

02-27-2012, 12:35 AM
You should add an event listener to the combobox instance for Event.CHANGE.

Example: If the instance name of the combobox is combo:
combo.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void {
if(combo.selectedIndex == 0) {
//first item selected
} else if(combo.selectedIndex == 1) {
//second item selected
} //...etc

It might be better (or more straightforward) to use a switch statement instead, but you asked about if, so I answered in those terms

Edit: but I see you asked about making your choice based on the text label, so that would be:
if(combo.selectedItem.label == "eyes") {

10-16-2013, 01:11 PM
I want to do this in actionscript 2 but have a second combobox selection changed based on the first combobox selection. Can you help? Thanks