Link to home
Start Free TrialLog in
Avatar of blueshoes
blueshoes

asked on

What event should I listen for to set focus to a component when a window first displays?

I implement a dialog window by using the PopUpManager to pop up a TitleWindow. After the window is popped up I want to set the focus to a specific control, and I have been putting the code for that in a method that handles the updateComplete event (and then removing that listener so that it will not intercept subsequent firing of that event). That worked well until a put a PopUpButton on the dialog that that pops up a tree control. Since then, the updateComplete event does not fire so that setting the focus in that event handler no longer executes.

Anybody know why the updateComplete event would not fire? Is there a better event to listen to for setting the initial focus?
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

I would suggest registering for FlexEvent.CREATION_COMPLETE ... this event is fired as soon as the components and all currently visible elements have been created.
Avatar of blueshoes
blueshoes

ASKER

Nope, creationComplete doesn't make it work. FWIW, my experiments show that the following three events fire in the order listed.
  1. creationComplete
  2. updateComplete
  3. focusIn
I have tried using all three with the same non-result. Attached is a screen shot of the dialog window. As you can see it is very simple. If I comment out the MXML code for the PopUpButton, the textInput.setFocus() works fine in a handler for any of the above events, but not if the PopUpButton is present.

????



DialogWindow.gif
ASKER CERTIFIED SOLUTION
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Christofer, thanks for taking a look at this, but never mind; I've found an alternative that works, namely, using the control's updateComplete event to set the focus to itself as follows.

                  <s:TextInput
                        id="textInput"
                        width="400"
                        text="{cardTitle}"
                        updateComplete="this.textInput.setFocus();"
                        />

I still don't know why it did not work using the TitleWindow's updateComplete event to set the focus to that control, and I would like to know why. But I'm moving on with this solution.
Christofer,

Oops. I didn't see your last post when I posted the above message saying "never mind." You suggested essentially what I discovered except that it appears to need to act on the updateComplete event rather than creationComplete.

Thanks.