|
-
Senior Member
help needed with clearInterval on multiple mc's
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
-
Senior Member
OK, this is what I have -
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;
}
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.
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.
-
Senior Member
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)
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;
}
***note*** That line in bold is only a suggestion and I havent even checked it to see if it works.
Post back with progess and I hope that helps
-
Senior Member
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!
-
Senior Member
glad to hear it helped. Drop a link when your done
-
Senior Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|