Return to Snippet

Revision: 9494
at November 10, 2008 11:56 by Winkyboy


Initial Code
// this code assumes the existance of a ComboBox (Components -> User Interface -> ComboBox) 
// on the stage with an instance name of "MY_DROPDOWN_INSTANCE_NAME" plus two items defined in its properties
// named "Choice One" and "Choice Two"

var MY_DROPDOWN_LISTENER:Object=new Object();  // a new listener
MY_DROPDOWN_INSTANCE_NAME.addEventListener("change", MY_DROPDOWN_LISTENER);  //add listener to combobox
MY_DROPDOWN_LISTENER.change=function(){  //function called
    // do something based on the selected item's label
    switch(MY_DROPDOWN_INSTANCE_NAME.getSelectedItem().label) {
        case "Choice One":
            trace("one");
            break;
        case "Choice Two":
            trace("two");
            break;
    }

    // do something based on the selected item's value
    switch(MY_DROPDOWN_INSTANCE_NAME.getSelectedItem().data) {
        case "Choice One":
            trace("one");
            break;
        case "Choice Two":
            trace("two");
            break;
    }
}

Initial URL

                                

Initial Description
I copied this from my working example and tweaked some lines to make it generic.  Thus there MAY be a typo which I haven't checked for, but probably not.  This is what's needed to have something change upon selection of an item in a ComboBox.

Initial Title
AS3 ComboBox "onSelect" changing

Initial Tags
dropdown, actionscript, 3

Initial Language
ActionScript 3