Select a Combo Box Value

Next, add a function to select a value in the combo box by its label.

You can copy this code from this page or download the source file here.

import flash.events.Event;
import mx.events.ListEvent;

/**
 * Select a value in a combo box
 * @param  id     id attribute of the combo box to use
 * @param  label  label to select in the combo box
 * @return        true if there was no exception, false otherwise
 */
private function selectByLabel(id:String, label:String):Boolean { 
  var combo:ComboBox, retval:Boolean = false;
  try {
    combo = ComboBox(getElementById(id));
    combo.selectedItem = label;
    combo.dispatchEvent(new ListEvent(ListEvent.CHANGE));
    retval = true;
  }
  catch(e:Error) {
  }
  return retval;
}