Issue with setFocus method of UIComponent in Flex

984 views Asked by At

I am facing one issue related to setFocus() method of UIComponent. I have one textinput and I have written textInput.setFocus() on creationComplete of application i.e.

private function onCreationComplete():void {

 // 1st approach     
 textInput.setFocus();

 // 2nd approach
 textInput.focusManager.setFocus(textInput); 
 textInput.focusManager.showFocus();

}

While using both the approach, I can see that my text input has got a cursor which shows that it has got focus. But issue is that it doesn’t get any input from keyboard until or unless I click on text input manually.

Is this behaviour normal in Flex or is there any issue with Flash Player which I am using or any issue with browser ?

Flex SDK: 4.1

Browser & Flash Player Version

  1. IE 9 with Flash Player debugger version 11.3.300.257...
  2. Chrome 15.0.874.121 with Flash Player 11.1.102.55...
  3. Firefox 20.0.1 with Flash Player 11.9.900.117...

Can anyone please let me know what is the issue? Any input will be highly appreciated !

4

There are 4 answers

2
Subash Selvaraj On

Try this,

private function onCreationComplete():void {

 textInput.setFocus();

 textInput.setSelection(0,0);

}

Hope it helps.

1
Andrei On

You are setting focus to TextInput inside application, but when web page is loaded flash app doesn't have focus. That's why your app doesn't get any keyboard events.
Try to search how to set focus onto flash app on page load.

Example:
How do I make my flash object get focus on load?

0
UI Dev On

Try this. In mxml you can give

focusEnabled = true

Hope it will help

5
Sumit On

This one is working for all broswers(IE, firefox and chrome) In your index.template.html file add the follwing script block

<script>
    function setFocusOnFlash() {
      var f=swfobject.getObjectById('yourFlashObjectId');
      if (f) { f.tabIndex = 0; f.focus(); }
    }
</script>

And call it onload in body tag

<body onload="setFocusOnFlash()">    

On your applicationCreationComplete put below lines

focusManager.setFocus(textInput); 
textInput.focusManager.showFocus();