I would like a flash movie to have a button that closes itself if the viewer is watching full screen so silly old me thought that a simple
on (release) {
getURL ("javascript:self.close()");
}
would suffice. I have tried all the various permutations of window.close etc. and still my flash movie won't close but beeps at me annoyingly.

Any help would be gratefully appreciated.

nesh

PS. Am using Flash MX 2004

Dani AI

Generated

Short diagnosis and practical fixes for 's case: browsers will refuse to let embedded content close a top-level window unless that window was opened by script. That refusal is what causes the "beep" and the apparent failure when calling browser-close from inside a SWF. 's hint about quitting and 's note about projectors are on the right track — the right solution depends on whether the SWF runs inside the browser or as a standalone projector. See MDN on the browser rule for close: Window.close.

If you can control how the player page is opened, open the SWF page with JavaScript (so the window is script-created). Then expose a simple JS close function in that wrapper HTML and have the SWF call it. Example wrapper JS:

<script>
var playerWin = window.open('player.html','playerWindow','width=800,height=600');
function closePlayer() {
  playerWin.close();
}
</script>

Call that wrapper function from Flash (use ExternalInterface.call if your player supports it; otherwise AS2 fallbacks exist). Because the window was opened by script and the close is tied to a user action, browsers will allow the close.

If the SWF must be the controller and you cannot open the page by script, you cannot reliably force the browser to quit. The remaining options are: run as a projector (standalone EXE) so the player can quit itself, or change the UX so the hosting HTML has a visible close link or instructions to exit full-screen. Test across browsers — behavior differs and modern browsers are stricter.

Caveats: closing the user's main browser window is poor UX and may still be blocked. Prefer opening a separate player window when you need programmatic close control.

Recommended Answers

All 2 Replies

Member Avatar for Member #46692

Do you mean make the browser switch from full screen mode and then close?

Or maybe this:

on(press,release){
fscommand ("quit");
}
Member Avatar for Member #114696

it really won't work since it couln't intract with your browser. You could close only if you are using a projector file to view that swf with

fscommand("quit", "");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.