The setInterval function

  • chazmonro
  • Newbie
  • Newbie
  • chazmonro
  • Posts: 8

Post 3+ Months Ago

So I'm new here, been working on a simple flash project where I load in 15 icons into duplicated movie clips. I have all that working, I simply use a for loop to duplicate the movie clip and set the image (inside the movie clip it loads the image) The problem is that I would like there to be an interval between each duplication. So inside the for loop I'd like it to pause for a second or so. Is it possible using the setInterval function? Or should I go about it an entirely different way? Please don't flame me, just looking for some advice.

Chuck
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

You can't pause a for loop, but you are on the right track with setInterval.

setInterval basically calls a defined function at the interval you need (in milliseconds). So if you define a function that duplicates your clip in the way that your for loop would and call that function using a setInterval it will work that way. But always remember to clear your interval!


QUick example....

Code: [ Select ]
var i= 0;
function increment(){
  i++;
  trace(i);
  if (i>5){
    trace("completed");
    clearInterval(myInterval);
  }
}
myInterval = setInterval(increment, 1000);
  1. var i= 0;
  2. function increment(){
  3.   i++;
  4.   trace(i);
  5.   if (i>5){
  6.     trace("completed");
  7.     clearInterval(myInterval);
  8.   }
  9. }
  10. myInterval = setInterval(increment, 1000);

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 13 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.