all groups > flash actionscript > may 2004 >
You're in the

flash actionscript

group:

setInterval: help w/ my code


setInterval: help w/ my code yn
5/28/2004 8:13:02 PM
flash actionscript: Seems I can never keep setInveral straight in my head. I've managed the code
below but the action still isn't what I have planned. Basically, all I want is
for a _mc to be duplicated and start a random motion ...in a timed interval.
Every second or so, a new _mc is created and shot out into the stage for its
random motion path. I guess you might visualize it as a really crummy particle
spray?

anyway, the code is below. thanks in advance for any suggestions that may
come. Some characters may drop from my copy/paste into this thread (well, it
use to do that a few months back. maybe it's fine now) but the code in general
is working. All except for the fact my clips are duplicating at the same time
as opposed to one after another.

click click click :)
noel


function myMotion() {
this.onEnterFrame = function(){
this.xpos += Math.floor(Math.random(5)*3)-2;
this.ypos += Math.floor(Math.random(5)*2)-2;
this._x += this.xpos;
this._y += this.ypos;
}
}

circ1_mc._visible = 0;
function circWait() {
for (i=1; i<=6; i++) {
circ1_mc.duplicateMovieClip("circ" +i+ "_mc", i, circ1_mc);
myMotion.call(eval("circ" +i+ "_mc"));
trace("circ"+i+"_mc");
}
clearInterval(myInterval);
}

myInterval = setInterval(circWait, 400);


Re: setInterval: help w/ my code Pete The Chop
5/28/2004 8:46:22 PM
The problem is the 'for' loop. For loops occur all at the same time, so it's
creating 6 movie clips and it's done. remove the for loop and it should work.
If you only want 6 of them, you should put a counter++ inside the circWait()
function followed by

if(counter==6){
clearInterval(myInterval);
}

Hope that helps!
AddThis Social Bookmark Button