setInterval.

  • shendel101
  • Born
  • Born
  • shendel101
  • Posts: 2

Post 3+ Months Ago

how to call setInterval to loop again after the clearInterval? example.. if i press button i want to call the loop again do its function. Thanks..
  • dhonsvick
  • Beginner
  • Beginner
  • dhonsvick
  • Posts: 49

Post 3+ Months Ago

here is how I do it

Code: [ Select ]

var myInt;
startInterval();
var who:Array = new Array("He","She","I","ME");

function startInterval(){
  clearInterval(myInt); // clear the interval, to make sure you dont over lap...which has interesting results ;)
  myInt = setInterval(this, "myFunction", 1000);
}

function stopInt(){
  clearInterval(myInt);
}



function myFunction(){
    var randomNum:Number = Math.floor(Math.random() * (3 - 0 + 1)) + 0;
 trace( who[randomNum]+" likes to Move it , Move it");
}
  1. var myInt;
  2. startInterval();
  3. var who:Array = new Array("He","She","I","ME");
  4. function startInterval(){
  5.   clearInterval(myInt); // clear the interval, to make sure you dont over lap...which has interesting results ;)
  6.   myInt = setInterval(this, "myFunction", 1000);
  7. }
  8. function stopInt(){
  9.   clearInterval(myInt);
  10. }
  11. function myFunction(){
  12.     var randomNum:Number = Math.floor(Math.random() * (3 - 0 + 1)) + 0;
  13.  trace( who[randomNum]+" likes to Move it , Move it");
  14. }


Now you can start Interval with - startInterval()

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 9 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.