Full Window Flash (With Minimum Dimensions), Done Right

2011-03-08 – Updated and now at:

http://dev.firefallpro.com/full-window-flash/

Original Article:

So you want to have Flash take up 100% of the browser window, but it also has to maintain minimum dimensions so content won’t be hidden if the window isn’t large enough. This will give Flash the ability to expand and contract as the user resizes the window, but if they make it too small scroll bars will appear. Achieving this involves a multistep process in order to properly support the most browsers (Safari, Firefox 2 & 3, IE 5 through 7).

Step 1: Create Your Container HTML File

Starting out with a HTML 4.01 Strict file is essential in creating a consistent experience. It’s time to get used to conforming to standards unless you want to mess around with multiple box models. No, you cannot use XHTML, no one should use it. Almost no one serves it properly and IE 6 has no clue what application/xml is. All you’ll do is force IE to render in quirks mode and use its box model.

Here is the start of a HTML 4.01 strict document as generated by BBEdit.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"        "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Full Window Flash With Minimum Dimensions</title> <meta name="generator" content="BBEdit 9.0"></head><body>

</body></html>

Step 2: Embed Your Flash with SWFObject 2

SWFObject 2 is a free JavaScript library that provides the ability to uniformly embed Flash while maintaining standards compliance and cross-browser support. I strongly urge you to check out the documentation as this article won’t go into any depth about its use.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"        "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Full Window Flash With Minimum Dimensions</title> <meta name="generator" content="BBEdit 9.0"> <script src="js/swfobject.js" type="text/javascript"></script> <script type="text/javascript"> <!--  swfobject.registerObject("flash_holder","7.0.19","swf/expressInstall.swf"); //--> </script></head><body> <div id="content">

  <!-- BEGIN: Flash Embed -->  <object id="flash_holder" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%">   <param name="movie" value="flash.swf">   <param name="quality" value="high">   <param name="scale" value="noscale">   <!--[if !IE]>-->   <object type="application/x-shockwave-flash" data="flash.swf" width="100%" height="100%">    <param name="quality" value="high">    <param name="scale" value="noscale">   <!--<![endif]-->

    <!-- BEGIN: Alternate Content -->    <div>Adobe Flash is required to view this website. Please <a href="http://www.adobe.com/go/EN_US-H-GET-FLASH/" onclick="window.open(this.href); return false;">install</a> it and reload this page.</div>    <!-- END: Alternate Content -->

   <!--[if !IE]>-->   </object>   <!--<![endif]-->  </object>  <!-- End: Flash Embed -->

 </div></body></html>

Between the head tags the SWFObject JavaScript file is referenced, followed by the function call itself. Between the body tags two nested objects are used along with some IE conditional comments. If none of this makes any sense, you probably still need to read the SWFObject documentation. The important thing is to set the width and height of the both objects to 100%.

Stopping here would create a nicely embedded Flash file that will resize with the window. Though a little CSS needs to be added to make it properly fill the window.

Step 3: The CSS

CSS needs to be added to make sure the Flash fills the entire window. There are a variety of issues with full window content, the specifics which I no longer recall, so you’ll just have to trust me for the most part.

Add within the head tags the following CSS:

 <style type="text/css"> <!--  html,  body,  div#content {   width: 100%;   height: 100%;  }

  body {   padding: 0;   margin: 0;   background-color: #FFFFFF;  }

  div#content,  object {   overflow: hidden;  } --> </style>

Now the Flash should take up the entire window. Though this doesn’t yet solve the problem of enforcing a minimum size when a user resizes the window. The user could shrink the window down and miss important elements, but Flash has no way of telling the browser that needs to maintain a certain size. A little CSS is all it takes to address that in modern browsers.

 <style type="text/css"> <!--  html,  body,  div#content {   width: 100%;   height: 100%;  }

  body {   padding: 0;   margin: 0;   background-color: #FFFFFF;  }

  div#content,  object#flash_holder {   min-width: 800px;   min-height: 600px;  }

  div#content,  object {   overflow: hidden;  } --> </style>

There is some over-specification in there because of a Safari bug.

I purposefully said modern browsers, because IE 6 and below have no idea what min-width or min-height even is. Chances are forgoing IE 6 support is not a likely option.

Step 4: Making Up for It with JavaScript

Even though IE 6 doesn’t support the CSS that would make this process complete doesn’t mean it has to get any more difficult. I created a JavaScript function called minsize()* to emulate the absent behavior.

<head>...<script src="js/minsize.js" type="text/javascript"></script>...</head>

The function takes the ID of the element you want to set minimum dimensions to, followed by the width, then the height. It should be wrapped in a IE conditional statement and placed at the end of the document before the closing body tag.

<!--[if lte IE 6]><script type="text/javascript">minsize('content',1000,750);</script><![endif]-->

*Please do not redistribute this file. The credits within need to remain intact. I also ask to be notified of any changes or improvements so I can update and repost the file as needed.

Step 5: Dealing with “Click to Activate”

Certain versions of IE will display a message around a Flash embed saying that it must be clicked to activate. This is due to that whole patent mess. Microsoft eventually licensed the patent so not every version of IE is effected. This can also be solved with another JavaScript workaround that should be included at the end of the document before the closing body tag, wrapped in IE conditional comments.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"        "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Full Window Flash With Minimum Dimensions</title> <meta name="generator" content="BBEdit 9.0"> <style type="text/css"> <!--  html,  body,  div#content {   width: 100%;   height: 100%;  }

  body {   padding: 0;   margin: 0;   background-color: #FFFFFF;  }

  div#content,  object#flash_holder {   min-width: 800px;   min-height: 600px;  }

  div#content,  object {   overflow: hidden;  } --> </style> <script src="js/minsize.js" type="text/javascript"></script> <script src="js/swfobject.js" type="text/javascript"></script> <script type="text/javascript"> <!--  swfobject.registerObject("flash_holder","7.0.19","swf/expressInstall.swf"); //--> </script></head><body> <div id="content">

  <!-- BEGIN: Flash Embed -->  <object id="flash_holder" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%">   <param name="movie" value="flash.swf">   <param name="quality" value="high">   <param name="scale" value="noscale">   <!--[if !IE]>-->   <object type="application/x-shockwave-flash" data="flash.swf" width="100%" height="100%">    <param name="quality" value="high">    <param name="scale" value="noscale">   <!--<![endif]-->

    <!-- BEGIN: Alternate Content -->    <div>Adobe Flash is required to view this website. Please <a href="http://www.adobe.com/go/EN_US-H-GET-FLASH/" onclick="window.open(this.href); return false;">install</a> it and reload this page.</div>    <!-- END: Alternate Content -->

   <!--[if !IE]>-->   </object>   <!--<![endif]-->  </object>  <!-- End: Flash Embed -->

 </div><!--[if lte IE 7]> <script src="js/clicktoactivate.js" type="text/javascript"></script><![endif]--><!--[if lte IE 6]> <script type="text/javascript">  minsize('content',800,600); </script><![endif]--></body></html>

I hope you’ve enjoyed scrolling to the end of this document as much as I did writing it. Here are the referenced files:

Now at: http://dev.firefallpro.com/full-window-flash/

Completed HTML
minsize.js (1.0.001)
clicktoactivate.js
SWFObject

Please send me comments on how I can improve this process or minsize.js. I will try to keep this document up-to-date and expand it if necessary.

16 Responses to “Full Window Flash (With Minimum Dimensions), Done Right”

  1. Cory says:

    Awesome tip(s), thanks for the help!

  2. Manuel says:

    Just wanted to say thanks. I was struggling to make this work in Safari, and you solved it.

  3. Joan says:

    Thank you for this excellent article. I enjoyed reading it to the end. 😀

  4. Rodrigo.LloReda says:

    Thanx man! excellent and simple to follow tutorial, works like a charm.

  5. Joe says:

    What it the licensing for this code? Can I use it in commercial products? And if so, is there any documentation stating the licensing, or can I get some thing that states that the code is free to use for commercial products?

    Thanks!

  6. Scott says:

    You may use this code commercially provided that credit's stay intact and you send back any sort of revisions or fixes. Naturally this applies only to our JavaScript and CSS reference, all other code is open-source and owned be their respective parties (i.e. SWFObject). The code may be incorporated in other works but should not be individually resold or rebranded.

    Lastly if you do happen to use it on a site, please post a comment if possible. We'd love to see where people are using it.

  7. Joe says:

    Cool, thanks! I'll be using it for a stock flash template on ActiveDen.net (formerly FlashDen.net).

    I'll post a link here after it's up on there.

    (Let me know if for some reason I misunderstood you and I shouldn't use this for that purpose).

    Thanks again!

  8. Anonymous says:

    Great code. However, I am running into problems when inserting "full screen" toggle into my flash site, via AS3. Debugging in Flash CS3 shows that the button works, but when I publish it into your html and view it with Firefox or IE, the button does not work (though it remains as a button). It has worked with different scripts I've tried in Opera, but never in FF or IE. Am I missing something? Kindly post when you can [open to all].

  9. Scott says:

    Regarding the full screen button. I haven't had the opportunity to try the combination. There shouldn't be anything in what I made that would stop it from working. Do you have an example anywhere?

  10. […] updated the Full Window Flash (With Minimum Dimensions), Done Right post. It now properly supports Firefox 3 and has been retested against Safari and IE 5 through 7. I […]

  11. ChristianC says:

    I had tried everything with CSS but never solved it before, Thank you very much for this. But I have just one question. I’m testing it on Chrome for Mac, but the flash seems to be trimmed. The scrollbars appears and I can scroll but the flash is cut out to the current size of the window.
    There’s any new update for this? Thank you.

  12. Hi,

    • Safari – working great.
    • IE – wokring great.
    • Firefox – sais that I need to install Flash (Firefox sais that only with this specific page though, Flash content form other sites is shown correctly).
    • Chrome – shows an empty white page, but no rightmouse menu is shown (nothing happens when you right-click, very strange)

    Here is my link, it’s for testing only:
    http://www.levroi.nl/1)%20NEW/index.html

    Thanks a lot for your efforts, that’s really great.
    Greetings form the Nethelrands!

  13. Stefan says:

    @Remco de Vries We staged the swf you used to test and were able to reproduce the errors in chrome and firefox. We are gonna look into it soon

  14. […] original article “Full Window Flash (With Minimum Dimensions), Done Right” is now it’s own page. The original article is still useful for a procedural […]

  15. Thank you very, very much! Oddly, I never had to do this until recently 🙂