5 Replies Latest reply on Jan 20, 2010 1:40 PM by kglad

    setInterval question

    velocity-vector

      hello --

       

      i use setInterval that tell an animation to wait 500 ms before going to the next frame...

       

      setInterval (this, "nextFrame", 500);
      clearInterval();

       

      now i want it to wait 500 ms before going to the next snippet of code. how do i do this?

       

      /*//

      I tried this method but to no avail

                function waitHalfSecond () {
                 clearInterval(myInterval);
                 myInterval = setInterval(waitHalfSecond, 500);
                }

      //*/

       

      /* OLD CODE */

       

      stop();

      attachMovie("bottom_btn_mc","bottom_btn_mc", 7,{_x:0, _y:0});

      bottom_btn_mc._alpha=0;
      bottom_btn_mc.onEnterFrame = function () {
      this._alpha += 14;
      if (this._alpha >= 90) {
        delete this.onEnterFrame;
      }
      }

       

      setInterval (this, "nextFrame", 500);
      clearInterval();

       

      /////////////////////////

       

      /* NEW CODE */

       

      stop();

      attachMovie("bottom_btn_mc","bottom_btn_mc", 7,{_x:0, _y:0});

      bottom_btn_mc._alpha=0;
      bottom_btn_mc.onEnterFrame = function () {
      this._alpha += 14;
      if (this._alpha >= 90) {
        delete this.onEnterFrame;

      /*// setInterval code here, wait 500 ms, then execute next line //*/

        attachMovie("spread_home_txt","spread_home_txt",8,{_x:4, _y:22});
        spread_home_txt._alpha=0;
        spread_home_txt.onEnterFrame = function () {

          this._alpha += 14;
          if (this._alpha >= 90) {
            delete this.onEnterFrame;
           }
          }

        }
      }

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

          what exactly are you trying to do?

          • 2. Re: setInterval question
            velocity-vector Level 1

            instead of going to the next frame and playing the code, i want to incorporate all the code in just frame 1.

             

            i need to wait a half second before loading *spread_home_txt*, instead of just depending on the onEnterFrame after the *bottom_btn_mc* loads.

             

            hope that makes sense. thanks > mark

             

            /* code in frame 1 */

             

            stop();

            attachMovie("bottom_btn_mc","bottom_btn_mc", 7,{_x:0, _y:0});

            bottom_btn_mc._alpha=0;
            bottom_btn_mc.onEnterFrame = function () {
            this._alpha += 14;
            if (this._alpha >= 90) {
              delete this.onEnterFrame;
            }
            }

            setInterval (this, "nextFrame", 500); // go to the next frame after a half-second
            clearInterval();

             

            /* code in frame 2 */

             

            stop();

            attachMovie("spread_home_txt","spread_home_txt",8,{_x:4, _y:22});
            spread_home_txt._alpha=0;
            spread_home_txt.onEnterFrame = function () {
            this._alpha += 14;
            if (this._alpha >= 90) {
              delete this.onEnterFrame;

            }

            }

            • 3. Re: setInterval question
              kglad Adobe Community Professional & MVP

              all code whose execution you want to delay, put in a function.  call that function using setTimeout(), if the code need only execute once.  use setInterva() is you want the code to execute repeatedly.

               

              p.s.  to clear a setInterval(), you must assign a variable to the setInterval and use that variable in your clearInterval() function:

               

              codeI=setInterval(codeF,234);

              // clearInterval(codeI);

              • 4. Re: setInterval question
                velocity-vector Level 1

                thanks --

                 

                this is how i applied the setInterval (works fine)...

                 

                attachMovie("bottom_btn_mc","bottom_btn_mc", 7,{_x:0, _y:0});
                bottom_btn_mc._alpha=0;
                bottom_btn_mc.onEnterFrame = function () {

                     this._alpha += 14;
                     if (this._alpha >= 90) {
                          delete this.onEnterFrame;

                     }

                }

                 

                function waitHalfASecond () {
                     attachMovie("spread_home_txt","spread_home_txt",8,{_x:4, _y:22});

                     spread_home_txt._alpha=0;

                     spread_home_txt.onEnterFrame = function () {
                          this._alpha += 14;
                          if (this._alpha >= 90) {

                               delete this.onEnterFrame;

                          }

                     }
                clearInterval(timerInterval);
                }
                timerInterval = setInterval(this, "waitHalfASecond", 500);

                • 5. Re: setInterval question
                  kglad Adobe Community Professional & MVP

                  you're welcome.