# Fade Functions - Sometimes React Slowly

**URL:** <https://forum.kirupa.com/t/fade-functions-sometimes-react-slowly/118379>\
**Category:** Uncategorized\
**Created:** [August 4, 2004, 9:52pm UTC](https://forum.kirupa.com/t/fade-functions-sometimes-react-slowly/118379 "2004-08-04T21:52:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sixfortyfive](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sixfortyfive/32/671_2.png) [@sixfortyfive](https://forum.kirupa.com/u/sixfortyfive)\
**Post date:** [August 4, 2004, 9:52pm UTC](https://forum.kirupa.com/t/fade-functions-sometimes-react-slowly/118379/1 "2004-08-04T21:52:20Z")

</div>

I wrote these functions to fade 3 movieClips in and out. There are three buttons- 1, 2, and 3, and each fade in and out their relative movieclip.

The problem is that when I click through the buttons, sometimes one might fade in, but one of the others doesn’t fade out. Or sometimes the one that is supposed to fade out does, but it is delayed.

Here are my functions:

```auto
function fadeIn(x){
  	if (x._alpha < 100) {
  		x.onEnterFrame = function() {
  			x._alpha += 10;
  		};
  	} else {
  		delete x.onEnterFrame;
  	}
  }
  
  function fadeOut(z){
  	if (z._alpha > 50) {
  		z.onEnterFrame = function() {
  			z._alpha -= 10;
  		};
  	} else {
  		delete z.onEnterFrame;
  	}
  }

```

Here are my button actions:

```auto
Button1:
  on (release) {
  	_root.content.fadeIn(_root.content.content_group1);
  	_root.content.fadeOut(_root.content.content_group2);
  	_root.content.fadeOut(_root.content.content_group3);
  }

```

Buttons 2 & 3 have similar code.

Any ideas?

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [August 4, 2004, 11:03pm UTC](https://forum.kirupa.com/t/fade-functions-sometimes-react-slowly/118379/2 "2004-08-04T23:03:28Z")

</div>

> [@sixfortyfive](#):
>
> I wrote these functions to fade 3 movieClips in and out. There are three buttons- 1, 2, and 3, and each fade in and out their relative movieclip.
> 
> The problem is that when I click through the buttons, sometimes one might fade in, but one of the others doesn’t fade out. Or sometimes the one that is supposed to fade out does, but it is delayed.
> 
> Here are my functions:
> 
> ```auto
> function fadeIn(x){
> if (x._alpha < 100) {
> x.onEnterFrame = function() {
> x._alpha += 10;
> };
> } else {
> delete x.onEnterFrame;
> }
> }
>   
> function fadeOut(z){
> if (z._alpha > 50) {
> z.onEnterFrame = function() {
> z._alpha -= 10;
> };
> } else {
> delete z.onEnterFrame;
> }
> }
> 
> ```
> 
> Here are my button actions:
> 
> ```auto
> Button1:
> on (release) {
> _root.content.fadeIn(_root.content.content_group1);
> _root.content.fadeOut(_root.content.content_group2);
> _root.content.fadeOut(_root.content.content_group3);
> }
> 
> ```
> 
> Buttons 2 & 3 have similar code.
> 
> Any ideas?

I can see what you are trying to do but how you have set the functions up, you are not deleting the onEnterFrame.(By the way changing \_alpha is heavy on processor anyway)  
Try changing to something like this  
function fadeOut(z) {  
z.onEnterFrame = function() {  
if (this.\_alpha\>50) {  
this.\_alpha -= 10;  
} else {  
delete this.onEnterFrame;  
}  
};  
}

---

<div class="post-metadata">

**Author:** ![sixfortyfive](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sixfortyfive/32/671_2.png) [@sixfortyfive](https://forum.kirupa.com/u/sixfortyfive)\
**Post date:** [August 5, 2004, 2:56pm UTC](https://forum.kirupa.com/t/fade-functions-sometimes-react-slowly/118379/3 "2004-08-05T14:56:17Z")

</div>

I ended up using code from [this[url=“http://www.kirupaforum.com/forums/showthread.php?t=47367”] post](http://www.kirupaforum.com/forums/showthread.php?t=47367):

```auto
function fadeIn(myMovieClip:MovieClip) {
 myMovieClip._visible = true;
 myMovieClip.onEnterFrame = function() {
 if(myMovieClip._alpha >= 100) {
 myMovieClip.onEnterFrame = null;
 } else {
 myMovieClip._alpha += 10;
 }
 }
 }	  
 
 function fadeOut(myMovieClip:MovieClip) {
 myMovieClip._visible = true;
 myMovieClip.onEnterFrame = function() {
 if(myMovieClip._alpha <= 0) {
 myMovieClip.onEnterFrame = null;
 } else {
 myMovieClip._alpha -= 10;
 }
 }
 }

```

This works perfectly!
