# \[FMX\]swapDepths inside function

**URL:** <https://forum.kirupa.com/t/fmx-swapdepths-inside-function/110236>\
**Category:** Uncategorized\
**Created:** [May 13, 2004, 3:57pm UTC](https://forum.kirupa.com/t/fmx-swapdepths-inside-function/110236 "2004-05-13T15:57:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)\
**Post date:** [May 13, 2004, 3:57pm UTC](https://forum.kirupa.com/t/fmx-swapdepths-inside-function/110236/1 "2004-05-13T15:57:34Z")

</div>

I have a function to fade in and out four movie clips. This is the code:

```auto
function fadeSub(l) {
 for (k=0; k<but.length; k++) {
  if (k != l) {
   this["sub_"+but[k]].onEnterFrame = function() {
	this._alpha += (0-this._alpha)/3;
	if (this._alpha < 5 ) {
	 this._alpha = 0;
	 delete this.onEnterFrame;
	}
   };
  } else {
   this["sub_"+but[k]].onEnterFrame = function() {
	this._alpha += (99-this._alpha)/12;
	if (this._alpha > 98) {
	 this._alpha = 99;
	 delete this.onEnterFrame;
	}
   };
  }
 }
}

```

I call the function with:

```auto
 clip.onRelease = function() {
  fadeSub(this.i);
 };

```

I have buttons inside the sub\_mc’s that aren’t working because of the depths. How doI integrate a swapDepth in the fadeSub function?

Donald
