Posted on

Embed SWF

This is the most cross browser compatible solution I have come up with thus far: ditch the object tag.
EmbedSWF resizes the target container, adds an optional background, then uses an innerHTML rewrite to populate it with the proper embed tag.
HTML: <div id=”swfbox”><!‐‐ swf gets inserted here by EmbedSWF ‐‐></div>

USEAGE: Specify the target ID, the full path to the swf file, width, height, optional background, and optional FlashVars:
Use a set of empty quotes for the background if you want to leave it blank but still include FlashVars, otherwise both are optional.

To have the page initialize with a file pre-loaded, place a script in a hidden p tag above the target div (if excluded, div content will show):
<p style=”display:none;”><script type=”text/javascript”>EmbedSWF(‘targetID’,’../mymedia/NewFile.swf’,600,400,’#000′,’file=this&buffertime=that&variable=something’);</script></p>
AND/OR include multiple links to load more swf files by placing script calls inside of link tags:
<p><a href=”#” onclick=”EmbedSWF(‘targetID’,’../mymedia/NewFile.swf’,600,400,’#000′,’file=this&buffertime=that&variable=something’);”>Load SWF</a></p>

function EmbedSWF(t,p,w,h,b,v){
if (b==null) {b=’none’};
document.getElementById(t).style.width=w+”px”; document.getElementById(t).style.height=h+”px”; document.getElementById(t).style.background=b;
document.getElementById(t).innerHTML=”<embed width=’100%’ height=’100%’ src=”+p+” type=’application/x-shockwave-flash’ quality=’high’ wmode=’transparent’ align=’center’ allowscriptaccess=’always’ allowfullscreen=’true’ pluginspage=’’ FlashVars='”+v+”‘></embed>”;

Here I’m using swf game files as an example

Choose A File!

Leave a Reply