Groups | Blog | Home
all groups > flash (macromedia) > october 2007 >

flash (macromedia) : Help with time delay


atraintobrkln
10/17/2007 9:03:45 PM
clbeech
10/17/2007 9:40:47 PM
you can use an Interval to start a function repeatedly over time, and set your
MCs that you want to laod into an array. something like this:


stop();

var holder = this.createEmptyMovieClip('holder', 0);
var array = ['clipA_mc', 'clipB_mc', 'clipC_mc', ... , 'clipZ_mc'];
var count = 0;
var timer = setInverval(addMC, 5000); //five seconds delay

function addMC() {
if(count<array.length) {
holder.attachMovie(array[count], array[count], count);
}else{
clearInterval(timer);
}
}
atraintobrkln
10/19/2007 5:20:18 PM
I am able to get this to load the MC but it seems to load them all at the same delayed time what am I doing wrong. I would like to stager each of the MC's out over the selected times.

clbeech
10/19/2007 7:08:01 PM
well, let's see, you could stop and then restart the interval with a new 'time'
variable on each attachment. You could either calculate the next time, or
select the next value or pick one randomly from an array, or however you would
like.

So you could let's say you want to just pick a random time greater than two
seconds and less than five, you could do something like this:


stop();

var holder = this.createEmptyMovieClip('holder', 0);
var array = ['clipA_mc', 'clipB_mc', 'clipC_mc', ... , 'clipZ_mc'];
var count = 0;

function done() {
clearInterval(timer);
addMC();
delay = 2000 + Math.round(Math.random()*3000);
timer = setInterval(done, delay);
}
//start the delay function
done();

function addMC() {
if(count<array.length-1) {
count++;
}else{
count=0;
}
holder.attachMovie(array[count], array[count], count);
}
atraintobrkln
10/19/2007 8:45:33 PM
clbeech
10/19/2007 11:28:07 PM
AddThis Social Bookmark Button