Close Button in a Flash Fly-Ad (HowTo)
I’ve just finished designing and implementing a semi-transparent flash advertisement for a website, and boy I spent a lot of google time trying to solve the following problem. How do you close a flash movie embedded in a HTML layer using its close button?
Well, the solution proved to be just a little more counterintuitive that I thought, but in few words I would resume it as follows:
The close button on those flash fly-ads doesn’t actually close the ad itself, but instead triggers a script inside the html that hides the layer containing the flash file.
So, just in case it would prove useful for someone in the same situation I was yesterday, here’s…
How to Make a Close Button in a Flash Fly-Ad (Pop-Up) Actually Work
Step 1. Create your Flash movie, and don’t forget to add it a [X] close button, or you’ll make my entire post useless!
Add the following action to the close button:
on (release) {
getURL ("j*vascr*pt: hideLayer('Layer1')", "_self");
}
and export your .fla movie to a .swf file. You might also want to chek the Publish Settings, and to make the necessary adjustments you deem fit, before you export.
Step 2. Create a layer and embed in it the flash movie (.swf file). Make all the necessary adjustments to fit your project (i.e. div style and layer ID, flash cabinet version, file paths, etc.).
Step 3. Insert the following javascript code in your html’s section, preferably right before the tag.
<script language="JavaScript" type="text/JavaScript">
<!--
function hideLayer(Layer1) {
if (document.getElementById) {
// this is the way the standards work
document.getElementById(Layer1).style.visibility = "hidden";
}
else if (document.all) {
// this is the way old msie versions work
document.all[Layer1].style.visibility = “hidden”;
}
else if (document.layers) {
// this is the way nn4 works
document.layers[Layer1].visibility = “hidden”;
}
}
//–>
</script>
Step 4. Save and preview (or upload). You’re done!
Leave a Reply