I’m working in a Flex project and the client asked for some Keyboard Shortcuts. It works great on Google Chrome and IE but, for some reason, Firefox doesn’t handle embedded objects focus correctly sometimes.
To “fix” this problem, I found a really nice workaround. First, you have to open your application on some browser and look at the source code. Then, look for the <object> tag “id” attribute inside it. If you use the default Flex template, it will probably be your Application name. In my case, it’s “index”. So I wrote this JavaScript line to set the focus on your application again:
1 | document.getElementById('index').focus(); |
Now, to use it on your code without rewriting your template, you can do this:
1 2 | navigateToURL(new URLRequest("javascript:try{ document.getElementById('index').focus(); void(0); }catch(err){}"), "_self"); someComponent.setFocus(); |
It works better if you try to identify when your application is loosing the focus (always when I opened a popup, in this case) and put the code after that. I also used a try/catch to avoid problems, like if the user opened the SWF directly.
I hope it helps someone!
Bye o/
Greeeeat tip!!!
very good example, and look what I’m doing hours after something like that, I tried various internet but without success
, this time it worked!
Felipe
Web Development
Marau – Rio Grande do Sul – Brasil
[...] Estava eu a tempos procurando um código eficiente para setar o foco na minha aplicação, pois tinha um Formulario de Login em cima do meu index e simplesmente não tinha cristo, após o código abaixo, funcionou na hora. O post original se encontra em aqui [...]