Layering flash and html tutorial
Jana asked for tutorial on layering HTML over Flash, so here is how the current footer works, though it will be replaced real soon.
Warning
This will only display correctly on Mac and *nix machines 50% of the time. There is a bug in the flash plugin that randomnly assign which element will be above the other in stacking order, no matter what you do with z-index or source order. So if you scroll up and down or referesh the page, the order may change.
There are also problems with Flashbock plugin for Firefox, overlaying HTML over flash currently makes it impossible to play the flash file. However, a solution may be at hand.
First you need SWFobject to handle the IE Eolas patent problem and providing alternative content to browsers without the right/any flash plugin.
In the head of your HTML page add:
<script type="text/javascript" src="swfobject.js"></script>
or the correct path to the SWFobject javascript
In the body of your HTML add:
<div id="container">
<div id="swfobject-to-replace">
<div id="alternative-content"></div>
</div>
<script type="text/javascript">
// <![CDATA[
var so = new FlashObject("flash-file-name.swf", "id-for-flash", "width in px", "height in px" , "flash_version_req", "background_colour");
so.addParam("wmode", "transparent");
so.write("swfobject-to-replace");
// ]]>
</script>
<div id="html-overtop">
</div>
</div>
the alternative-content could by an img instead of a div
the script is straight from the SWFobject only added bits is you must have a height and width as numbers (do not end in px or similar) the default is pixels but you can change that in your style sheet.
the html-overtop div (or other block element) can contain whatever you want.
And in your CSS add
#container { position: relative; }
#id-for-flash, #alternative-content { position: absolute; top: 0; left: 0;}
#container, #id-for-flash, #alternative-content { height: X; width: Y;}
#html-overlay{ z-index: 2; }
And that is play safe (only assumption the HTML overlay is smaller or the same size as the flash), note the height and width do not have to be in pixels, I use EMs for this blog.
How it works:
- If you have the required version of flash, SWFobject replaces the div id #swfobject-to-replace with the flash object #id-for-flash
- The flash object is taken out of the normal flow of the document, and absolutely positioned to the first positioned parent element (hence #container requires position: relative;)
- The html div #html-overlay is in the normal flow of the document, and is positioned normally in relation to div #container
- The z-index on #html-overlay is not really needed, because without the z-index, source order counts and #html-overlay is after and therefore above #id-for-flash. But because #id-for-flash is outside the order, you can never to safe.
12 Oct: At WD06, well sitting outside a pub after a few drinks, having a cigarette, James Edwards explained the solution to the Mac OsX flash player problem is to use an iframe shim, so once I have experimented with it, I will post the solution.
July 4th, 2006 at 12:54 am
Your site looks like it provides good information but is extremely difficult to read because of the large text size. You should consider using a standard text size.
August 17th, 2006 at 8:59 pm
I totaly agree about the font sizes, they’re really hard to read.
September 20th, 2006 at 6:05 am
Try resizing your browser window guys.
November 15th, 2006 at 7:31 am
use ctrl+scroll )
November 15th, 2006 at 7:33 am
so what about working demo?
Nick: This whole blog is a working demo of this technique, if you are using Firefox, use view source to see the pre rendered version of the page and use the view source chart extension to see what happens after the javascript does it’s and the flash files inserted.
If you are using a mac or *nix box, scroll down to the bottom of the page and you might see the footer. Scroll up and down again, it might appear or disappear.
March 1st, 2007 at 9:35 pm
I don’t want to have to resize my browser. You need to change it for a standard view as opposed to trying something new. There are already standard protocols on the web. “Catch-up”.
March 13th, 2007 at 3:12 am
This only seems to work when you set window mode (‘wmode’) to transparent.
But why do you need the flash movie to be transparent if it is behind the html content?
If you set wmode to ‘window’ or omit the wmode parameter, the flash movie is placed on top of the html content, ignoring the z-index attribute.
Do you know of a way to keep the opaqueness (no transparency) and still be able to place the html content on top?
March 13th, 2007 at 9:13 pm
Reiner, I wanted to use flash for background vector images, usually over tiled bitmap background images. Hence the use of wmode transparent. Unfortunately it only works in flash player for windows. wmode transparent in flashplayer for mac or linux has a few problems.
I don’t know of a way to place HTML over flash with wmode window, though an iframe shim may do it.
March 22nd, 2007 at 4:21 am
Don’t be losers. The header/footer resizing is pretty cool when you size the type.
May 1st, 2007 at 11:19 pm
i already tried the iframe idea.. and i didn’t have much luck with it.. still tweeking t hings though…
July 18th, 2007 at 3:03 am
Hey everyone,
Does anyone have an answer for the problem reinier brought up on March 13th?
I’m having the same issue as I cannot change the wmode of the flash? I have been searching this issue for a while now and it seems like the problem could have something to do with the layer losing focus to the flash and then the flash shows on top? Anyone knows a way how to keep the focus on the layer at all times?
Thanks
July 29th, 2007 at 7:22 am
[…] Tutorial to layer Flash and HTML […]
October 10th, 2007 at 4:12 am
how about the dreamweaver AC-Runactivecontent plugin instead of swfobject ?
October 12th, 2007 at 5:46 pm
Tom, I do not use dreamweaver regularly, so I know very little about AC_Runactivecontent. It appears to solve the IE Eolas patent problem. However, it does not provide alternate content to visitors without the flash plugin, ie iPhone users. That is the advantage of SWFobject.
April 7th, 2008 at 5:25 pm
iPhone dont support flash
April 8th, 2008 at 6:06 pm
Anon that is why you provide alternative content, for devices that do not support flash.
ps when the iPhone does support flash, it will have the same problem as other *nix browsers, see the first two paragraphs. So alternative comment is by far the lesser of two evils.
July 1st, 2008 at 4:44 pm
Am I missing something? Where is the div#container you speak about? It’s not in th HTML, so why is its style defined in your CSS?
July 1st, 2008 at 6:07 pm
Thanks! I’ll give it a try!
September 4th, 2008 at 5:45 pm
Oops! my mistake, the code example above is now fixed.
September 25th, 2008 at 2:40 pm
The text is great! It is E Z to read!
April 4th, 2009 at 12:35 am
Thanks for this article. Very useful info…