Joshua Patton
Joshua Patton

Reputation: 462

Pause flash game using javascript

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.

Upvotes: 2

Views: 2433

Answers (3)

back2dos
back2dos

Reputation: 15623

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.

Upvotes: 2

zenazn
zenazn

Reputation: 14345

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

Upvotes: 1

Şafak Gezer
Şafak Gezer

Reputation: 4007

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)

Upvotes: 3

Related Questions