I need a function or some way to create a pause in between calls to a function and setInterval doesn’t seem to be working.
Basically, I have several movie clips in the library named movie1, movie2, etc… Each contains a fading movie clip. I want to attach them all using actionscript, but i want to wait like 5 secs in between each one and i can’t seem to get it to do that.
Here is the code i have so far without setInterval. It cause them all to appear on the screen at once.
var numOfEmployees = 4;
for (var i=1; i <= numOfEmployees; i++) {
var thisName = “movie” + i;
attachClip(thisName);
}
function attachClip(thisName){
thisMovie = _root.attachMovie(thisName, thisMovie + i, this.getNextHighestDepth())
thisMovie._x = 100;
thisMovie._y = (_root._height - thisMovie._height) - 100;
}
Now, this will make all movie clips appear on screen at the same time. What is the best way to create a 5 second delay between each call to attach clip? What is the proper way to use setInterval or is their a better way??
I need a solution that doesn’t use the timeline at all, possibly just a function that would work like this…
for (var i=1; i <= numOfEmployees; i++) {
var thisName = “movie” + i;
attachClip(thisName); wait(5);
}
yes you do it with setInterval . basically you have to do smth like this:
counter = 0;
function wait(){
trace ("each 5 seconds you get this crappy message");
}
setInterval(wait, 5000);
this will trace that message each 5 seconds.
now you can implement it to your code by simply changing the wait from setinterval to your function - attach clip.
so it is like this
counter = 0;
function wait(){
trace ("each 5 seconds you get this crappy message");
}
setInterval(attachClip, 5000);
note that the interval is 5000. the interval is expressed in milliseconds. so 5000 milliseconds = 5 seconds. that is if you want to make some changes to the timing.
function wait(sec) {
// This function will pause playback for the number of seconds passed in
trace("Waiting for "+sec);
var sec:Number;
var offset:Number;
stop();
sec *= 1000;
offset = getTimer();
onEnterFrame = function () {
if((getTimer()-offset) > sec){
play();
delete onEnterFrame;
}
};
}
It’s designed to halt the timeline its called from.
Google setInterval() - like krityx said it’s the proper way to do it. It’s specifically made for delaying and/or calling functions at specific “set intervals”.