views:

405

answers:

2

I have developed a simple interactive Flash game, but now it appears that sometimes Flash Adds (3rd party ones displayed by facebook) somehow steal the focus from my flash application (by mistake?). My app has textfield() where the focus should remain until game is over.

My flash object uses urlrequest/javascript to ask for focus at startup (it works with IE and Firefox) but it seem that focus can be easily stolen. What should I do to get the focus always back when its lost and/or how to make sure other flash app is not stealing it?

Also my javascript focus request is currently not working with Safari/Crome browser, so what is most compatible way to request focus and keep it?

+1  A: 

When I absolutely need focus I normally just have the player click something in the flash to give it focus, it doesn't even need to be "click here to focus" but rather a start button or something like that.

actionscript3 also has an event that fires when your app looses focus, you can use this to pause the game and pop up a box requesting the player to give focus back.

I think that "forcing" the focus will be unreliable at best and you will need a proper fallback regardless.

As a sidenote; I've never had the issue of "stealing focus", and I'm not even sure i understand why the ads could/would do this?

grapefrukt
well, my game is pretty intensive, so I would like to stop 3rd party add interrupts game *several times* per minute.. Is there anything to do to avoid stealing focus.This seems to be FLASH *specific* issue, when my game was JAVA APPLET based there was no focus problem caused by 3rd party Adds.
Tom
+1  A: 

I've never had to deal with your specific situation (and I've never heard of it happening either, but nore have I had to fight with other Flash objects on a web page), but what if you were to listen for MouseEvent.FOCUS_OUT on your text field and then set a one-shot timer for, say, 250ms, which upon firing would then take the focus back (using whatever JavaScript you might need to convince the browser to give you the focus again).

Unfortunately I don't know enough about integration with Safari or Chrome to help you with your second question.

erikprice