Search code examples
actionscript-3apache-flexfocusmanager

setFocus in Flex


I'm Using following code in flex4 mxml That works fine.

<mx:Button label="Set focus to Username"
            click="focusManager.setFocus(username);" />

How to use the same in Action script I mean creation complete event of an application without using button.

That is I have login panel in application While page loads the username field should focused having cursor in it.

Can any one help me?


Solution

  • The issue is that within your application the TextInput has focus, but within the HTML page your Flex application does not. So basically the only extra step you need is to give the Flex app focus. There's only one way to achieve this: through JavaScript. And you should do it after the application was loaded.

    The guys at Farrata wrote a very good example on how to do this, so I'm just going to point you there: http://flexblog.faratasystems.com/2011/12/15/setting-focus-in-flex-components