• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to add a delay to a loop?

Guest
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.
TOPICS
ActionScript

Views

484

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 13, 2008 Oct 13, 2008

Copy link to clipboard

Copied

LATEST
I need it to, thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines