6 Replies Latest reply on Nov 22, 2010 11:22 AM by kglad

    Time event question

    gaminflash

      Hi, after watching the thread:

      Repeat function after x seconds?

      I have a question about the time event, can you make something disabled for an amount of seconds too? For an example: you have a variable that you want to go "false;" if you click "Right" or something, and after a second or so the variable go "true;" again. What i actually want to achieve here is that during an animation a variable makes you disable so you can't for an example play the "attack" animation while the "walk" animation is on.

        • 1. Re: Time event question
          kglad Adobe Community Professional & MVP

          yes, you can use setTimeout() to delay a call to any function:

           

          var bool:Boolean=false;

          setTimeout(resetF,3000);

           

          funciton resetF(){

          bool=true;

          }

          1 person found this helpful
          • 2. Re: Time event question
            Ned Murphy Adobe Community Professional & MVP

            If it is a one shot deal, then you can use setTimeout().  When you click whatever intiates setting whatever variable to be false, also initiate a setTimeout(someFunction, 1000); call so that in one second someFunction is called and sets the value true again.

            1 person found this helpful
            • 3. Re: Time event question
              gaminflash Level 1

              Sorry but i dont really get it, i tried this in the movieclip:

               

              onClipEvent(load){
              moveable = true;

              speed = 3;
              }
              onClipEvent(enterFrame){

               

              if(Key.isDown(Key.UP)){
              moveable = false;

              }

              if(Key.isDown(Key.LEFT) && moveable == true;){

              this._x -= speed;

              }

               

              and in the frame:

               

              if(var moveable:Boolean=false){

               

              setTimeout(resetF,1000);

               

              function resetF(){

              moveable=true;

              }

               

              What did i do wrong :S?

              • 4. Re: Time event question
                kglad Adobe Community Professional & MVP

                those two code snippets are in different scopes.

                 

                remove the code from your movieclip and attach it to a frame.  there's never a reason to attach code to an object and there are many reasons to avoid doing that.

                 

                your_mc.speed=3;

                your_mc.moveable=true;

                 

                your_mc.onEnterFrame=function(){

                if(Key.isDown(Key.UP)){
                this.moveable = false;

                setTimeout(resetF,1000,this);

                }

                if(Key.isDown(Key.LEFT) && this.moveable){

                this._x -= speed;

                }

                }

                 

                 

                function resetF(mc:MovieClip){

                mc.moveable=true;

                }

                • 5. Re: Time event question
                  gaminflash Level 1

                  Thank you very much! You solved the problem. There were only a few things in the script that i changed, as you can see in the clear script here:

                   

                   

                  speed=3;

                  moveable=true;

                   

                  a.onEnterFrame=function(){

                  if(Key.isDown(Key.UP)){
                  moveable = false;

                  setTimeout(resetF,1000,moveable);

                  }

                  if(Key.isDown(Key.LEFT) && moveable == true){

                  this._x -= speed;

                  }

                  }

                   

                   

                  function resetF(a:MovieClip){

                  moveable=true;

                  }

                   

                  P.S the movieclip is "a"

                  • 6. Re: Time event question
                    kglad Adobe Community Professional & MVP

                    you're welcome.