# setInterval.

• shendel101
• Born
• Joined: Aug 23, 2007
• Posts: 2
• Status: Offline

August 30th, 2007, 1:05 am

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..
• Anonymous
• Bot
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

August 30th, 2007, 1:05 am

• dhonsvick
• Beginner
• Joined: May 27, 2007
• Posts: 49
• Status: Offline

August 30th, 2007, 9:01 pm

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 45 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

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.