Setting the default button in a Flex application from actionscript
When you need to set defaultButton property dynamically depending on who has focus, you can not use the defaultButton property that every container component has but must use focusManager instead.
For instance, I have a search box input that when it has focus I need the enter button to do the search. This behavior needs to be different if the search box doesn’t have input as there are lots of other boxes with their own functions that need to be triggered on Enter.
For this I setup the focusIn and focusOut eventson the text input:
<s:TextInput x=“10” y=“68” editable=“true” width=“141” id=“mainArtistNameInput”
and just enable disable the default button in the event handlers:
protected function searchInput_focusOutHandler(event:FocusEvent):void
focusManager.defaultButton = null;
protected function searchInput_focusInHandler(event:FocusEvent):void
focusManager.defaultButton = searchMainArtist;
setting the default button for the container from actionscript, does nothing. You could of course do all this inline.
If you just want to remove the defaultButton so no button is being pressed when you tap Enter, jsut set focusManager.default button to null;