The easiest way to include Adobe Flash SWFs in your sites

Inserting Flash into your web pages

In order to place Flash .swf files in your pages, you need a bit of special code. The code is fairly complex so I have written a bit of JavaScript to simplify the process. In reality, all you should have to know to put an animation in your page are three things:

  • The name of the .swf document
  • The width of the object
  • The height of the object
 
<script type="text/javascript" >
function writeFlash(movieLocation,mywidth,myheight,myname) {
if (myname) { myid=myname; } else { myid="flashanimation"; }
	document.write('<object type="application/x-shockwave-flash"id="'+myid+'"width="'+mywidth+'"height="'+myheight+'"data="'+movieLocation+'"> <param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+movieLocation+'" /><param name="quality" value="high" /><param name="scale"value="noscale" /><param name="wmode" value="transparent"/></object>');
}
</script>
<script type="text/javascript" >
	writeFlash('mymovie.swf',width,height);
</script>

If you want to use this on multiple pages, you should copy the first piece of code containing the function and put it on a separate text file. When you do, make sure you DON'T include the beginning and ending <script> tag. Let's say we call the new text file we created "writeflash.js", so in the <head> tag, write the following.

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

You can place this code on any webpage that will need to call the .SWF file. If you have a header file that loads on every page on your site, it would be easier to place it there.

blog comments powered by Disqus