Sunday, November 16, 2008

Focus in all cases

Have you also noticed that Flex draws a focus border around its components when you give them focus using the keyboard (by using the tab button)?

Great but why is the focus border not drawn when using the mouse to give a component the focus?

The solution is simple: extend the existing components and force the border drawing yourself:

<mx:CheckBox
      xmlns:mx="http://www.adobe.com/2006/mxml"
      focusIn="onFocusIn()">
<mx:Script>
//
// Support to draw the focus border on focusIn
//
private function onFocusIn(): void
{
      this.drawFocus(true);
}
</mx:Script>
</mx:CheckBox>

2 comments:

Anonymous said...

Don't know Flex but can't you simply create new controls based on the existing ones and including this focusIn extension?
Having to add this to every control in an application looks like a little pain in the ass to me...

Ria Flex said...

That's exactly what I do. It has to be done for every UI control however but as you can see: the amount of code that needs to be written is very small.