# Simple function question

**URL:** https://forum.kirupa.com/t/simple-function-question/183565
**Category:** Uncategorized
**Created:** [March 28, 2006, 9:42am UTC](https://forum.kirupa.com/t/simple-function-question/183565 "2006-03-28T09:42:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![co2la](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@co2la](https://forum.kirupa.com/u/co2la)
#### Post date: [March 28, 2006, 9:42am UTC](https://forum.kirupa.com/t/simple-function-question/183565/1 "2006-03-28T09:42:53Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Gumby19](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gumby19](https://forum.kirupa.com/u/Gumby19)
#### Post date: [March 28, 2006, 6:40pm UTC](https://forum.kirupa.com/t/simple-function-question/183565/2 "2006-03-28T18:40:19Z")

</div>

This might work.

```auto

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

```

---

<div class="post-metadata">

### Author: ![co2la](https://avatars.discourse-cdn.com/v4/letter/c/4bbf92/32.png) [@co2la](https://forum.kirupa.com/u/co2la)
#### Post date: [March 28, 2006, 7:28pm UTC](https://forum.kirupa.com/t/simple-function-question/183565/3 "2006-03-28T19:28:34Z")

</div>

worked perfectly… thanks!
