Possible to close the browser?


(David Williams) #1

This isn’t really a Flashpunk question at all, but more so a very specific general AS3 question.
Is it possible to close the current browser window/tab using AS3? I’ve tried:

		if (Input.pressed(Key.ESCAPE))
		{
			trace("Shutting down...");
			navigateToURL(new URLRequest("javascript:window.opener=self;window.close ();"));
			System.exit(0);
		}

The “System.exit(0);” bit is for testing locally. The navigateToURL is what I read on StackOverflow, but I couldn’t seem to get it to work. It just makes my browser tab start flashing white. Maybe it’s just the browser behaving oddly? (Firefox-Windows?) Does it work for anyone else? Try clicking on the swf anywhere and then pressing Escape.


(Ultima2876) #2

Nope - this is a security feature. Imagine if a flash ad could close your browser window or start opening links at will. The internet would be a pretty horrible place indeed.


(rostok) #3

@Deamonr - you should embed your SWF in HTML. Only then you can access javascript. However closing window will display confirmation dialog box.

@Ultima2876 - opening new windows is absolutely possible from flash (both browser and stand alone player). And you don’t even have to do it from user event handler (like in case of file io)


(rostok) #4

ok, it seems ultima was right about closing windows. apparently you can’t do this unless it is the window that you previously opened.


(Ultima2876) #5

If you try to open a new browser window outside of a mouse click event, popup blockers will block it 99% of the time.


(David Williams) #6

I just wanted to bind the Escape Key to closing the ‘program’ for a school related project. Looks like I am unable to do that. thanks for the info.


(Ultima2876) #7

If it’s for school, deploy it to desktop with adobe AIR and use NativeApplication.exit().


(Matt L) #8

Beat me to it. If this is going to be a desktop app then just use AIR. Then you can do whatever you want, more or less. Using AIR instead of Flash requires zero code changes most of the time. All of my flashpunk games compile as Flash and AIR/AIR Mobile with zero changes.