Flash Content and allowFullscreen

We recently put a Letter Quest demo on Newgrounds. It’s doing very well, with great ratings and lots of plays (7000 in just under two days!). But one important thing you need to realize when you post a game on Newgrounds…

Your game will get posted on other sites. A lot of them. And the more popular that your game is, the more sites you’ll see it pop up on suddenly (at the time of this writing the Letter Quest demo is on over 15 sites that we didn’t post it to).

Now, it’s not a bad thing when your game gets spread around the internet, especially when it’s a free demo. What is bad is when you have a button in your game that allows the player to switch between fullscreen and windowed, and the site hosting your game decides to set allowFullscreen to false in their index.html. It’s even worse when you fail to account for that in your code, and the game throws an error whenever someone clicks that nice (now evil, nefarious, nasty) fullscreen button.

Luckily there’s a pretty simple fix – a huge thank you to Sarah Northway for her reply on stackoverflow about how to detect if that flag is set. Basically you can detect if it’s set using

if (stage.hasOwnProperty("displayState") && stage.hasOwnProperty("allowsFullScreen") && stage["allowsFullScreen"])
{
	// fullscreen allowed
}
else
{
	// fullscreen not allowed
}

So I simply added that check, and if fullscreen is not allowed, I don’t bother showing the fullscreen/windowed toggle button. Problem solved. Well, mostly…

IMPORTANT: As Sarah notes, the property that this code checks was added in Flash Player 10.2, so in older versions of Flash Player, it won’t give you a reliable result (but it won’t crash). So I also added some extra code to handle the case where the button is still visible, and fullscreen is not allowed, and in that case I catch the error and then set a global flag saying that fullscreen is not allowed.

The only catch here is that most Flash gaming sites that borrow (steal?) your game’s swf will actually make a copy of it. So upgrading the swf on Newgrounds was only part of the battle. I also contacted the owners of each site that is hosting the game, and asked them to manually update to the new swf. Surprisingly, every single one of them got back to me within a day and updated their swf for the game – I was really impressed, thanks for being awesome everyone! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *