0
How to add a delay to a loop?

/t5/animate-discussions/how-to-add-a-delay-to-a-loop/td-p/844019
Oct 11, 2008
Oct 11, 2008
Copy link to clipboard
Copied
I want to repeatedly add a movie to the stage using add child
so have created a loop to add it 30 times. How can I make it so
they aren't all added at the same time. I'd like to be able to set
an interval of time between them being added.
Thanks.
Thanks.
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/animate-discussions/how-to-add-a-delay-to-a-loop/m-p/844020#M19425
Oct 11, 2008
Oct 11, 2008
Copy link to clipboard
Copied
Something like this would do:
var atimer:Timer = new Timer(500,30);
atimer.addEventListener(TimerEvent.TIMER,addone);
atimer.start();
function addone(e:TimerEvent){
var anmc:MyMovieClip = new MyMovieClip();
addChild(anmc);
}
As that stands the movieclips ("MyMovieClip" is the name you used when you set that symbol for sharing in the Library) would be added every half second, but they would all be on top of each other. You probably would want to set the anmc.x and anmc.y to the position you need before doing the addChild().
The event has a property called currentCount, which you could use to help figure out where this one gets placed. Like:
anmc.x = e.currentCount * 20;
would spread the 30 movieclips across the stage, 20 pixels further along each time.
var atimer:Timer = new Timer(500,30);
atimer.addEventListener(TimerEvent.TIMER,addone);
atimer.start();
function addone(e:TimerEvent){
var anmc:MyMovieClip = new MyMovieClip();
addChild(anmc);
}
As that stands the movieclips ("MyMovieClip" is the name you used when you set that symbol for sharing in the Library) would be added every half second, but they would all be on top of each other. You probably would want to set the anmc.x and anmc.y to the position you need before doing the addChild().
The event has a property called currentCount, which you could use to help figure out where this one gets placed. Like:
anmc.x = e.currentCount * 20;
would spread the 30 movieclips across the stage, 20 pixels further along each time.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/animate-discussions/how-to-add-a-delay-to-a-loop/m-p/844021#M19426
Oct 12, 2008
Oct 12, 2008
Copy link to clipboard
Copied
Hi,
Thanks a lot for this. It's brilliant. It does exactly what I want it to do and I can get loads of other great effects by making small adjustments to the code. You were right in predicting I would want it to move over the screen :)
Thanks again.
Thanks a lot for this. It's brilliant. It does exactly what I want it to do and I can get loads of other great effects by making small adjustments to the code. You were right in predicting I would want it to move over the screen :)
Thanks again.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
LATEST
/t5/animate-discussions/how-to-add-a-delay-to-a-loop/m-p/844022#M19427
Oct 13, 2008
Oct 13, 2008
Copy link to clipboard
Copied
I need it to, thanks
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

