setFocus Issue on TextInput – Solution

November 29, 2007

Some days back, I got a mail from a customer with a baffling problem. Consider this…

  • You have 3 TextInputs, adjacent in tab order in an application.
  • You type something on the first, press tab, again type something on the next and tab again
  • Now for some reason, you want the second tab to switch focus onto the first, instead of the last TextInput…

He wrote a listener for the focusOut event on TextInput2 and then wrote the following code in the listener function.

event.preventDefault();
stage.focus = txt1;
txt1.setSelection(txt1.text.length,txt1.text.length);

He expected this…

But got this…

After lots of digging, I found the solution, thanks to Sreeni 🙂

It seems that the problem is that though the application focus moves to TextInput1, the keyboard focus moves to TextInput3, as the keyboard foucs is moved before the focusOut method is called and we are able to call preventDefault() on it.

Sreeni dug out a KEY_FOCUS_CHANGE event which needs to be listened to, on TextInput2 and then repeated the above code for the event-listener method. So,

Instead of writing

<mx:TextInput id=”txt2″ focusOut=”setTxtFocus(event)”/>

You need to write the following code in the creationComplete Listener in AS

txt2.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, setTxtFocus);

Now you can repeat the same code for the setTxtFocus method and solve this issue… You can see the app and the solution code below

Application | Source


FLEX requirement at I.GEN Labs, Bangalore, India

November 29, 2007

Karthik from I.GEN Labs contacted me about an urgent FLEX requirement at their company. I think they are open to freelance options too. Here’s the excerpt from his mail to me…

I.GEN Labs is a consultation startup based in Bangalore handling some “small” projects for some of the biggest retailers in India. We are into building systems that we think are first of their kind in the retail sector.


The profile we are looking at apart from high enthusiasm and a strong desire to create is a solid working knowledge of Flex. Some basic knowledge of Databases will also make life easier.


Do let us know if you could help us find somebody. Our contact numbers are
Karthik.R – 9980005873
NIranjan. Murthy — 9986033579