6 Replies Latest reply on Sep 7, 2007 7:49 AM by kglad

    Reusing setInterval function within the same script

    Saywell
      I'm using the following code (which I took from the Components Language Reference help, them modified it to suit my app) to play a series of movies and load an image in to the movies with a 3 second interval. It works fine but I have a counter set up elsewhere in the script within an onEnterFrame function that is used to monitor when the movies finish playing. Once all the movies have finished, I need to run this function again, but I don’t know how to call it again.

      var intervalId:Number;
      var count:Number = 0;
      var maxCount:Number = noOfPhoto;
      var duration:Number = 3000;
      function executeCallback():Void {
      eval("bend"+k+"_mc").play();
      loadMovie(eval("imageName"+k), "bend"+k+"_mc.photo_mc.empty_mc");
      k++;
      if (count>=maxCount) {
      clearInterval(intervalId);
      }
      count++;
      }
      intervalId = setInterval(this, "executeCallback", duration);


      I’m a novice with action script and the only way I know how to do this is stick something like:

      runInterval = function (){
      var intervalId:Number;
      var count:Number = 0;
      var maxCount:Number = noOfPhoto;
      var duration:Number = 3000;
      function executeCallback():Void {
      eval("bend"+k+"_mc").play();
      loadMovie(eval("imageName"+k), "bend"+k+"_mc.photo_mc.empty_mc");
      k++;
      if (count>=maxCount) {
      clearInterval(intervalId);
      }
      count++;
      }
      intervalId = setInterval(this, "executeCallback", duration);
      };

      Then use runInterval(); within an if statement that will call the function again once the my counter for when the movies have finished has got to it’s desired qty, but it doesn’t work.

      Thanks

      Russell