To do this yourself, you should look at the following bits and pieces of code below from the ComboBox
and ListBase
classes. ListBase
is what the ComboBox
component uses for it's drop down list.
The ComboBox
appears to be deferring the keyboard input to the drop down list. It then listens for events from the drop down list to know when the selection has changed (as a result of keyboard or mouse input).
Flex components usually override a method called keyDownHandler()
to process the keyboard input when they have focus. Starting there, we come across ComboBox line 2231:
// Redispatch the event to the dropdown
// and let its keyDownHandler() handle it.
dropdown.dispatchEvent(event.clone());
event.stopPropagation();
So now the keyDownHandler()
in the drop down list will get executed. That method has a giant switch
statement, where the default
case statement on line 9197 of ListBase looks like this:
default:
{
if (findKey(event.charCode))
event.stopPropagation();
}
This is where the drop down list decides what to select based on keyboard input (when the input is not an arrow key or page up, etc.). The protected findKey()
method simply calls the public findString()
method to do this work.
So to override this behavior yourself:
- extend the
ListBase
class and override thefindKey()
orfindString()
methods with your custom logic - extend
ComboBox
class and override thecreateChildren()
method so you can instantiate your customListBase
class instead of the default one.