PDA

View Full Version : setInterval help / keeps running in diff frame


julzmon
03-29-2003, 03:30 AM
I have this script in a frame. The point of this is to move and rotate these blocks a second or two after the first one moves. Then I have a similar script with different coordinates in another frame. The problem is when i go to another frame with the different coordinates the squares twitch between the two coordinates. I can't seem to figure out how to cancel the setInterval.

Please help

block2move1 = function() {
block1.inside.Rotate(50, movingspeed);
block1.Move(500, 400, movingspeed);
}
block2move2 = function() {
block2.inside.Rotate(100, movingspeed);
block2.Move(500, 400, movingspeed);
}
block2move3 = function() {
block3.inside.Rotate(10, movingspeed);
block3.Move(450, 400, movingspeed);
}
block2move4 = function() {
block4.inside.Rotate(30, movingspeed);
block4.Move(400, 700, movingspeed);
}

setInterval(block2move1,1000);
setInterval(block2move2,2000);
setInterval(block2move3,3000);
setInterval(block2move4,4000);

updateAfterEvent()

craftymind
03-29-2003, 07:40 AM
block2move1 = function() {
block1.inside.Rotate(50, movingspeed);
block1.Move(500, 400, movingspeed);
clearInterval(interv1);
}
block2move2 = function() {
block2.inside.Rotate(100, movingspeed);
block2.Move(500, 400, movingspeed);
clearInterval(interv2);
}
block2move3 = function() {
block3.inside.Rotate(10, movingspeed);
block3.Move(450, 400, movingspeed);
clearInterval(interv3);
}
block2move4 = function() {
block4.inside.Rotate(30, movingspeed);
block4.Move(400, 700, movingspeed);
clearInterval(interv4);
}

interv1 = setInterval(block2move1,1000);
interv2 = setInterval(block2move2,2000);
interv3 = setInterval(block2move3,3000);
interv4 = setInterval(block2move4,4000);


you could shorten the script up alot using an array and a counter, but for now, the above should be fine.

senocular
03-29-2003, 09:48 AM
or you can use setTimeout - clearing itself after one call.
First though, since its not a native Flash function it needs to be defined, so put this in the first frame of your movie to define it:


_global.setTimeout = function(a,b,c, args){
// for a basic function call:
if (typeof arguments[0] == "function"){
args = arguments.slice(2);
var ID, func = function(){
a.apply(null, args);
clearInterval(ID);
}
ID = setInterval(func, b, args);

// for an object method call:
}else{
args = arguments.slice(3);
var ID, func = function(){
a[b].apply(a, args);
clearInterval(ID);
}
ID = setInterval(func, c, args);
}
return ID;
}
_global.clearTimeout = clearInterval;


Then replace your setIntervals there with setTimeout and they'll only run once.

julzmon
03-29-2003, 04:03 PM
perfect

thank you very much

Yorgi
02-01-2005, 03:26 PM
Wow.... senocular, I have no clue how that works, but it works perfectly for my project as well...