# Close floating flash advert script

**URL:** https://forum.kirupa.com/t/close-floating-flash-advert-script/118904
**Category:** Uncategorized
**Created:** [August 10, 2004, 4:28am UTC](https://forum.kirupa.com/t/close-floating-flash-advert-script/118904 "2004-08-10T04:28:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![danwangkw](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danwangkw](https://forum.kirupa.com/u/danwangkw)
#### Post date: [August 10, 2004, 4:28am UTC](https://forum.kirupa.com/t/close-floating-flash-advert-script/118904/1 "2004-08-10T04:28:24Z")

</div>

How do I script a button within a floating flash advertisement (embedded in a HTML page by means of layers) to close it (usually denoted by an ‘X’) without exiting the HTML page which embeds it?

Does the button simply make the layer invisible? Any help is appreciated.

Dan

---

<div class="post-metadata">

### Author: ![eki](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eki](https://forum.kirupa.com/u/eki)
#### Post date: [August 10, 2004, 10:35am UTC](https://forum.kirupa.com/t/close-floating-flash-advert-script/118904/2 "2004-08-10T10:35:55Z")

</div>

Yes, just copy and paste this script in the head of your html (note that te id of the layer containing the banner is “myLayer”)

```auto

<script type="text/javascript">
<!--
function findObj(n, d) { 
  var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms*[n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers*.document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showHideLayers() { 
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args*))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
	//alert("showHideLayers "+obj.visibility);
}
 function closeBanner(){
 	showHideLayers('myLayer','','hide');
}
//-->
</script>

```

and then call the close banner function from your button movieClip in flash:

```auto

myCloseButt.onRelease = function(){
   getURL("javascript:closeBanner()");
}

```

---

<div class="post-metadata">

### Author: ![danwangkw](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danwangkw](https://forum.kirupa.com/u/danwangkw)
#### Post date: [August 10, 2004, 12:01pm UTC](https://forum.kirupa.com/t/close-floating-flash-advert-script/118904/3 "2004-08-10T12:01:07Z")

</div>

Thanks! I’ll give it a shot.

Dan

---

<div class="post-metadata">

### Author: ![eki](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eki](https://forum.kirupa.com/u/eki)
#### Post date: [August 10, 2004, 12:12pm UTC](https://forum.kirupa.com/t/close-floating-flash-advert-script/118904/4 "2004-08-10T12:12:23Z")

</div>

any time
