Simple function question

I’m trying to figure out how to make sure a function completes before the next one starts. (a stupid question I know, but I’m still learning).

My objective is for the movieClip to fade out before it goes to the new frame and plays. In a movieClip I’ve placed the code (there are actually 15 buttons, I’m only showing 2 for this example):

onClipEvent (enterFrame) {
this.web01_btn.onRelease = function()
{
fadeOut();
_root.gotoAndPlay(“web01”);
};

this.web02_btn.onRelease = function() 
{
	fadeOut();
  	_root.gotoAndPlay("web02");
};

function fadeOut() {
var alpha_interval:Number = setInterval(fadeImage, 50, this);
function fadeImage(target_mc:MovieClip):Void {
target_mc._alpha -= 10;
if (target_mc._alpha <= 10) {
clearInterval(alpha_interval);
}
}
}

}

any help would be appreciated… thanks!

This might work.


onClipEvent (enterFrame) {
  this.web01_btn.onRelease = function() {
    _root.playVar = "web01"
    fadeOut();
  };

  this.web02_btn.onRelease = function() {
    _root.playVar = "web02"
    fadeOut();
  };

  function fadeOut(a) {
    var alpha_interval:Number = setInterval(fadeImage, 50, this);
    function fadeImage(target_mc:MovieClip):Void {
      target_mc._alpha -= 10;
      if (target_mc._alpha <= 10) {
        _root.gotoAndPlay(_root.playVar);
        clearInterval(alpha_interval);	
      }
    }
  }
}

worked perfectly… thanks!