views:

408

answers:

3

I'm working on a flash gaming site, BeardedGames.com. I just recently implemented a "Panic" button that makes the entire site display: none and display: block's a iframe with a allowed in school website of the user's choice.

It works well so far, but the user's flash game still runs in the background while hidden. Is there a way to pause (not reset) the game, that will work on most, if not all, flash games? It needs to be accessible from javascript (possibly just javascript, or a flash wrapper?), and it has to work in IE 6 and greater (I know... I know. Can't help it.).

EDIT: Failed to make it clear that the user must be able to "un-pause" their game after the unpanic button is pressed.

EDIT: I haven't made these games, these are already made games like linerider.

+2  A: 

I don't know if you can force pause a Flash movie with Javascript, but you can always create a pause function in the AS code of your Flash application, then call that function with Javascript. (try googling flash.external.ExternalInterface if you're using AS3)

Şafak Gezer
The problem is that the flash games are by other developers
Josh Patton
A: 

Check out myswf.StopPlay(). Got it from this tutorial, haven't tried it myself. YMMV.

zenazn
The example doesn't seem to work for me.
LiraNuna
I tested it, it doesn't work due to security restrictions in the file.
Josh Patton
Oh well. My guess is that due to security restrictions, nothing you try will work unless the game specifically enables it via an ExternalInterface call.
zenazn
+1  A: 

Best thing you can do:

Do not embed the games directly. Embed an swf, that'll load the game. Then you'll be able to have some control, because the loaded SWF is running in the same instance as the loading SWF. For most games, it should suffice setting the frame rate to 0.

Still, some games use timers, so while the game doesn't run visually, the game logics (partially) continue.

you can however combine this with drowntoge's solution. have the loader make a call to javascript, where you have some operation that blocks, for example have it making synchronous http requests until the unpanic button is pressed. some browser may however complain that the script is running too long. some browser may also halt all JavaScript execution or become unresponsive.

greetz

back2dos

back2dos