views:

1313

answers:

4

I am using an ExternalInterface call on activate from a flex application embedded within my html document. The call goes to a javascript function which does

function documentFocus() {
  this.focus();
}

Everything works like a charm, except that Firefox does not focus the document body 100%. It stops listening for onkeyup events (it still registers onkeydown).

Very odd behavior. Does anyone have a clue what is happening?

Try it here: http//www.willemdemmers.com/dplxr/

Steps to reproduce: Try arrow-buttons to see normal behavior (arrow images light up red on keydown and stop light on keydown) Click the flash at the bottom of the window to remove focus from the document body and invoke the function call. Try the arrow-buttons again and see the new behavior.

The key-events trigger from the arrow-keys (left and right).

Thanks!

A: 

I think the issue is that flash is greedy on the keyboard when it's clicked and grabs it away from you.

You can see this in action on ie youtube. when you select a video you can use the up and down arrows to scroll up and down the page. But when you click into the flash area (the video) you can no longer do this. Since flash grabs the keyboard.

Ólafur Waage
That is what I am trying to prevent with the function call. It works great in Safari but in Firefox it only works half-assedly
Willem
Try this SO question. http://stackoverflow.com/questions/789771/flash-flex-sdk-as3-how-to-keep-keyboard-focus
Ólafur Waage
A: 

Check this out: http://code.google.com/p/custom-context-menu/

It's a project which disables flash's right click with javascript, and tells flash when it does so. Additionally, it works on a very very wide number of browsers.

not a 100% solution, but you should be able to adapt their JS code for your needs

I am not having problems with right click. The problem is that in Firefox the this.focus() or document.body.focus() doesn't work as intended.
Willem
A: 

This is actually a long standing Firefox bug that I wish would be fixed. I don't remember the Mozilla bug number off hand.

James Ward
A: 

You may try to focus hidden (or absolutely positioned away) input element, and then focusing document. Because inputs are almost native elements, it could help.

skrat