This particular technique is not new by any means, but it is nice method of going full browser. By full browser I mean the entire viewing area of FireFox, Safari, IE, or whatever you view your web pages in. The method also uses swfobject to deploy your Flash content. If you’re not familiar with swfobject, view my previous post here. In summary, swfobject is now going to be the de-facto standard in Flash embedding. Adobe is now using it as their default embedding option in Dreamweaver CS4. In other words, it’s completely legit and something you should really get used to.
The Goal
I want to be clear on what we are trying to accomplish here and what technologies we are using. A quick Google search on any of these topics will yield a crap ton of results and not all of them are helpful. You would have to do a lot of piecing together to get what I have here, so don’t bother. Here is what we want to do:
- Use ActionScript 3 (AS3)
- Get full browser flash, but not full screen
- Use Swfobject as our means of Flash deployment
- Use a swf of static dimensions (eg. 800×600 that doesn’t expand or contract)
- Center horizontally
- Center vertically
- Have the browser display scroll-bars when the browser becomes smaller than the viewing area
If this is exactly what you were looking for then simply continue reading. If you are looking for a variation of this, you may still be able to tweak a couple things to get your desired result. Let’s do this.
Step 1 – Create your Flash file
Go ahead and open up Flash. Go into your document properties (command+J, or control+J) and make the document dimensions 800 x 600. Set your background color to black, #000000. You’re settings should look like this:

Document Properties
After you do that, go ahead and drag ruler guides in 50px from every side. This will give you a guide to draw out a rectangle that will act as your content area. Select the rectangle tool and draw out your rectangle within the new guides. I changed the fill to a bitchin’ blue gradient! Here is what you should now have:

Totally sweet blue radial gradient
Step 2 – The ActionScript
Now we need to go ahead and add our ActionScript. I prefer to enter everything into Document Classes, but you could just as easily add this to the first frame of your fla file.
package {
//For Display
import flash.display.*;
//For Events
import flash.events.*;
public class FullScreen extends MovieClip {
public function FullScreen() {
//This ensures that your flash content won't expand
//if the user expands the browser window.
stage.scaleMode = StageScaleMode.NO_SCALE;
//Listen for resizing
stage.addEventListener(Event.RESIZE, resizeHandler);
}
private function resizeHandler(event:Event):void {
/*
In this method you could choose to put specific instructions
telling certain display elements where they should be aligned.
For instance, you have a nav bar that you always want to be
20px from the top. You could do that here.
*/
}
}
}
Step 3 – Use Swfobject to generate our html file
I previously wrote an article explaining how to deploy your Flash content using swfobject. If you aren’t familiar with swfobject you should go read it.
You can go ahead and generate your html file like my previous tutorial says to get started. But we are going to have to swap out some code to achieve our desired results. Either open up your generated html file, or just start with a blank one and paste in the following code. This is the entirety of the html document so as not to leave any confusion.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
var params = {};
params.scale = "noscale";
var attributes = {};
swfobject.embedSWF("FullScreen.swf", "flash", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>
<script type="text/javascript">
//<![CDATA[
function getViewportSize() {
var size = [0, 0];
if (typeof window.innerWidth != "undefined") {
size = [window.innerWidth, window.innerHeight];
}
else if (typeof document.documentElement != "undefined" &amp;amp;amp;&amp;amp;amp; typeof document.documentElement.clientWidth != "undefined" &amp;amp;amp;&amp;amp;amp; document.documentElement.clientWidth != 0) {
size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
}
else {
size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
}
return size;
}
function createFullBrowserFlash() {
swfobject.createCSS("html", "height:100%;");
swfobject.createCSS("body", "height:100%;");
swfobject.createCSS("#flash", "margin:0; width:100%; height:100%; min-width:700px; min-height:500px;");
window.onresize = function() {
var el = document.getElementById("container");
var size = getViewportSize();
el.style.width = size[0] < 770 ? "700px" : "100%";
el.style.height = size[1] < 390 ? "500px" : "100%";
};
window.onresize();
}
swfobject.embedSWF("Preloader.swf", "content", "100%", "100%", "9.0.0");
if (swfobject.hasFlashPlayerVersion("9.0.0")) {
swfobject.addDomLoadEvent(createFullBrowserFlash);
}
//]]>
</script>
</head>
<body>
<div id="flash">
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
</body>
</html>
You can ignore most of the code. But, you’ll need to pay attention to where we’re telling swfobject that the dimensions of the swf file are 100% vertical and 100% horizontal. This gives us the full browser we are looking for. The other important thing to look at is the javascript dealing with the minimum height and width of our “stage.” I’ve chosen to take into account the 50px padding on all sides of our fla making the height 500px, and the width 700px. I did this because I don’t want scroll bars to appear until there is actual content being covered up.
Don’t worry, we’re almost there. We have one thing left to do, and that is write our CSS.
Step 4 – The CSS
It doesn’t matter if you import your CSS or write it into the header, but it should look like:
body {
padding:0;
margin:0;
background:#000; /*same color as your flash bg */
text-align:center;
}
#flash {
margin:0 auto;
width:700px; /* I only want scroll bars to appear when the window is smaller than the actual content */
overflow:visible;
vertical-align:center;
height:600px;
}
All Done
At this point you should be done! Congrats. You now have a full browser and centered Flash page. Pretty awesome right? Check out the example here.
For those lazy people who want the files
Here they are.