views:

259

answers:

1

[FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]

When I click with a mouse an TextField, I would like that another (editable) field gets focus, but currently focus is lost somewhere.. I dont know where focus is.

I made a listener to textfield which tries to set focus back to another filed with stage.focus = editfield but its not working.

I have also same focus listener in stage, but no difference.

+1  A: 

Since you list a "FocusEvent" in your example, I will focus on Flex solutions. That is not a Flash AS3 class.

I will wager that Flex is trying to manage the focus by itself and that is screwing with your attempts to set it. There are, however, a number of ways around this.

Is Flex trying to work against you?
First, you may want to either use FocusManager class or the UIComponent setFocus method (this depends on what you specifically need to do, I believe the FocusManager allows you to have multiple objects targeted, while the setFocus method is a good deal simpler) instead of stage.focus. This has the benefit of working natively within the Flex component system.

Are you listening to the right event?
Failing that, try making sure that the target of the FocusEvent you're looking for is neither your textfield nor a child of your textfield. (Just for sanity's sake). If that does not work, make sure you are only getting the event dispatched once.Next, I would try using MouseEvent.CLICK instead of a FocusEvent.

Has everything else failed?
Unfortunately, Flex is often far from perfect. I find that sometimes I have to use setTimeout to get around the fact that it does not fire events in the "right order" -- you resize something, but "RESIZE" is dispatched before it has re-rendered, you change the font, and a TextArea's TextWidth property doesn't return the right number. The workaround

private function myListener( event:FocusEvent ):null
{
    setTimeout( function(){ editfield.setFocus(); }, 35 );
}
Christopher W. Allen-Poole