Posted By

Winkyboy on 11/10/08


Tagged

select dropdown actionscript box 3 ComboBox selected


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

THEPWN3R
rahzizzle
tspitzr


AS3 ComboBox "onSelect" changing


 / Published in: ActionScript 3
 

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.

  1. // this code assumes the existance of a ComboBox (Components -> User Interface -> ComboBox)
  2. // on the stage with an instance name of "MY_DROPDOWN_INSTANCE_NAME" plus two items defined in its properties
  3. // named "Choice One" and "Choice Two"
  4.  
  5. var MY_DROPDOWN_LISTENER:Object=new Object(); // a new listener
  6. MY_DROPDOWN_INSTANCE_NAME.addEventListener("change", MY_DROPDOWN_LISTENER); //add listener to combobox
  7. MY_DROPDOWN_LISTENER.change=function(){ //function called
  8. // do something based on the selected item's label
  9. switch(MY_DROPDOWN_INSTANCE_NAME.getSelectedItem().label) {
  10. case "Choice One":
  11. trace("one");
  12. break;
  13. case "Choice Two":
  14. trace("two");
  15. break;
  16. }
  17.  
  18. // do something based on the selected item's value
  19. switch(MY_DROPDOWN_INSTANCE_NAME.getSelectedItem().data) {
  20. case "Choice One":
  21. trace("one");
  22. break;
  23. case "Choice Two":
  24. trace("two");
  25. break;
  26. }
  27. }

Report this snippet  

You need to login to post a comment.