Posted By

MMDeveloper on 09/18/08


Tagged

combo box selectedIndex


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

THEPWN3R


Set combo box selected item


 / Published in: ActionScript 3
 

URL: http://www.mechanicmatt.com

  1. Take a combobox with options, and an instance name of "myComboBox"
  2.  
  3.  
  4. private function findItemIndex (element:ComboBox, dataString:String):int {
  5. var index:int = 0;
  6. for (var i = 0; i < element.length; i++) {
  7. if (element.getItemAt(i).data.toString() == dataString) {
  8. index = i;
  9. break;
  10. }
  11. else {
  12. }
  13. }
  14. return index;
  15. }
  16.  
  17.  
  18. then to set the value and updated the selected item, just one line of code:
  19.  
  20. myComboBox.selectedIndex = this.findItemIndex(myComboBox, "stringToMatch");

Report this snippet  

You need to login to post a comment.