I'm using setInterval and clearInterval for setting and resetting (on reload) of speeds. This works fine when I have a single mc but when I have multiple mc's I can't seem to get the clearInterval to work.
Can anyone help me?
Printable View
I'm using setInterval and clearInterval for setting and resetting (on reload) of speeds. This works fine when I have a single mc but when I have multiple mc's I can't seem to get the clearInterval to work.
Can anyone help me?
post your code and give more info on your setup.
gparis
OK, this is what I have -
I've got a similar set up for my ship which works fine, the only difference is that the rocks are multiple mc's running of the same code. I'm guessing this will reset one rocks setInterval but not them all.Code://at start of frame
clearInterval(rockmove);
//function in the frame
function startrocks() {
rocksarray = new Array();
rocknumber = 0;
for (i=0; i<4; i++){
rockmc = newrock(100);
rockmc._x = 500*Math.random();
rockmc._y = 500*Math.random();
}
}
function newrock(scale){
rocknumber++ ;
rockmc = attachMovie("rock", "rock" + rocknumber, rocknumber);
rockmc._xscale = scale;
rockmc._yscale = scale;
rockmc.dx = (4*(Math.random()-0.5));
rockmc.dy = (4*(Math.random()-0.5));
rockmove = setInterval(moverock, 50, rockmc)
//store in array
rocksarray.push(rockmc);
//reset rockmc
return rockmc;
}
Anyone have a solution?
Someone else has suggested I us onEnterFrame instead, would that be easier? I have no experience with using it though.
Thanks for any help guys.
You dont have to use onEnterFrame. What I am seeing as a possible problem is when you use setInterval() you are setting "rockmove" as the controller ID for the interval. Using the same name for all of them may be leading to problems. I would try storing in an array the ID's of the interval as well and accessing them like that. Then, to clear them just pop off the one you want to clear or all of them (depending on what you want to do)***note*** That line in bold is only a suggestion and I havent even checked it to see if it works.Code:function newrock(scale){
rocknumber++ ;
rockmc = attachMovie("rock", "rock" + rocknumber, rocknumber);
rockmc._xscale = scale;
rockmc._yscale = scale;
rockmc.dx = (4*(Math.random()-0.5));
rockmc.dy = (4*(Math.random()-0.5));
rockIDarray.push(setInterval(moverock, 50, rockmc));
//store in array
rocksarray.push(rockmc);
//reset rockmc
return rockmc;
}
Post back with progess and I hope that helps :thumbsup:
Works perfect, thanks Driciotti! thants relieved me of one haeadache, just a few more to solve and I'll have a game ready for release!
glad to hear it helped. Drop a link when your done
I have a beta version at http://www.mandissected.co.uk/spacerocks.htm if you're interested. You'll have to forgive it being pretty basic, it's only my second game. Any feedback would be great.