Fade Functions - Sometimes React Slowly

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:

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:

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;
}
};
}

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

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!