Some Pixels en / pt

Firefox and the Flash/Flex focus problem

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:

document.getElementById('index').focus();

Now, to use it on your code without rewriting your template, you can do this:

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/