Thursday, December 18, 2008

Java Script Function to Show Flash Banner

Usually I develop Desktop Application. But sometimes I also get involve in Web Development. So we were developing a Website in which we were trying to create a Flash Banner rotator. To accomplish this there are several techniques, but I created the following Java Script function for our Web Developer.

function showflashbanner(htmlobjectid, flashfilename, width, height) {
var script;
script = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' " +
"codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' " +
"width='" + width + "' height='" + height + "' \>" +
"<param name='movie' " +
"value='" + flashfilename + "' /\>" +
"<param name='quality' value='high' /\>" +
"<embed src='" + flashfilename + "' " +
"quality='high' " +
"pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' " +
"type='application/x-shockwave-flash'" +
"width='" + width + "'" +
"height='" + height + "'\>'" +
"</embed\>" +
"</object\>";
document.getElementById(htmlobjectid).innerHTML = script;
}


Example:
<body onload="showflashbanner('bannercontainer', 'http://www.mywebsite.com/banners/banner1.swf', 720, 100)">
<div id="bannercontainer">Loading...</div>
</body>

As you can see the above example we have used "div" as a Banner container. Then we are passing this div's id in our function so the Flash File will be loaded in it.

The Web developer then used this function by creating an Array of Flash Files. He also created another function in which he used setTimeout function. So the function calls itself after some time with new Flash File.

No comments: