2 Replies Latest reply on Jun 24, 2007 7:49 AM by kglad

    How to wait until a function has finished

    Dj_Mario Level 1
      Im calling a function but i don't want to continue until it has finished. This is my code.
      So i want to wait to enable the menuUp button until fadeInButton function has finished.

        • 1. Re: How to wait until a function has finished
          Level 7

          Hi Mario,

          if you want to wait untill some fading is done, you need to poll for it
          every frame. The fadeInButton funtion is finished soon enough, but the
          onEnterFrame eventhandler is executing every frame and it is it's result
          you want to test for.

          But... you could probably best take a look at the Tween class (see
          Components Language Reference in the help). With it you can tween
          properties of a movieClip (including it's _alpha) and have the tween
          send a message through it's onMotionFinished event handler when it's
          finished. No need to poll for it every frame.

          HTH,
          Manno


          Dj Mario wrote:
          > Im calling a function but i don't want to continue until it has finished. This
          > is my code.
          > So i want to wait to enable the menuUp button until fadeInButton function has
          > finished.
          >
          >
          >
          > menuDown.onPress = function() {
          > if (!menuUp.enabled) {
          > fadeInButton(menuUp);
          > menuUp.enabled = true;
          > if (firstLook) firstLook = false;
          > }
          > }
          >
          > function fadeInButton(argButton:Button) {
          > this.onEnterFrame = function():Void {
          > argButton._alpha += fadeInSpeed;
          > if (argButton._alpha>=100) {
          > delete this.onEnterFrame;
          > argButton._alpha = 100;
          > }
          > };
          > }
          >

          --
          ----------
          Manno Bult
          http://www.aloft.nl
          • 2. Re: How to wait until a function has finished
            kglad Adobe Community Professional & MVP
            you already have a loop testing when fadeInButton is finished. put your menuUp.enabled statement there: