1 Reply Latest reply on May 7, 2009 1:59 PM by kglad

    setInterval complications when interacted by buttons: Mac 10.4, CS3, AS2

    Trouble07

      I have a slideshow I've built that uses setInterval to pause at each image. At each paused keyframe, a short animation plays (the animation is contained within an object which only exists at the single keyframe).

       

      The problem I used to have was that after the first time around (all images shown), the slideshow begins increasing in speed (not pausing for the full duration),  and eventually begins sparadically skipping pauses all-together. I rearranged the code, and fixed the speed-up/skipping problem, but now my advance and goBack buttons don't work right, and they cause skipping.

       

      My old code, which had working buttons but sped-up/skipped, is as follows:

       

      //code at each keyframe

       

      var myInterval = setInterval (pause_fnc, 5000);

       

      function pause_fnc () {     

           if (_currentframe !== _totalframes) {

                gotoAndPlay (_currentframe + 1);

           } else {

                gotoAndPlay (2);

           }

           clearInterval (myInterval);

      }

       

       

      //Code on the advance button

       

      on (release) {

           clearInterval(myInterval);

           backup = false;

           gotoAndPlay (_currentframe +1);

      }

       

      But as i said, the previous code, would skip and speed up after the first time through the full project.

       

      So I rewrote the code as such:

      //Code at initial Keyframe.

      //Each keyframe that needs to pause, from then on uses wait();

       

      function wait() {

           clearInterval(myInterval);

           stop();

           var myInterval = setInterval(function () {

                gotoAndPlay(_currentframe + 1);

                clearInterval(myInterval);

                }, pauseTime);

           }

           

      wait();

       

       

      But now, like i said, I don't know what code to put on my buttons. I don't know how to clear the interval of a nested function.

       

       

      Please help,

       

       

      Jeff