Applying focus to Flex application on startup

On a recent project we carried out some accessibility testing and one of the problems faced was with keyboard users who couldn’t use a mouse. After loading the application (by typing in the URL in the address bar) the users couldn’t tab to the input fields on the application, focus would never reach the flex app at all. After searching around I eventually found a little code snippet in a comment on Flex Examples.

 private function setApplicationFocus():void{
 navigateToURL(new URLRequest("javascript: document.getElementById(<DOM_ID>).focus();"), "_self");
 focusManager.setFocus();
 }
 

The above is called in the Application object on creationComplete.

Advertisements