• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 992
  • Last Modified:

Acrionscript 3.0 how to pause a for loop

I see the "almost" answer I need in a thread for AS2.0:

How would you do this for AS3.0 using the Timer?

So, my question is how do you get the timer to pause the for loop so the dynamic mcs can appear one at a time after a predetemined pause.

Thanks for your help.

BTW: Here is a copy of the answer for AS2 given in the above post:
//forget the for loop! Use only the timed functions:
var delay = 1000; // 1 second
var count = 0;
var timerId = setInterval(createMC,delay, this);
function createMC(obj){
        var thumb:MovieClip = obj.attachMovie("thumb", "thumb"+i, i, {_x:xPos, _y:yPos});
                  if(count >= _global.projThumb.length){

Open in new window

1 Solution
Well, in AS3, you just tell the timer to wait...If I understand your needs correctly.  Here's a good tutorial on the Timer class

and the code below illustrates the Timer class in relation to what you might need
var delay:uint = 1000; //delay is measured in milliseconds;
var numLoops:uint = projThumb.length; //numLoops would be some number of times you want the loop to run
var timr:Timer = new Timer( delay, numLoops );
timr.addEventListener(TimerEvent.TIMER, createMC);
private function createMC( event:TimerEvent ):void
   //create the MCs or whatever here

Open in new window

gtaffet08Author Commented:
Thank you. Your answer helped me to see what I was doing wrong and helped me to get my code to work. I didn't understand that I needed to use the timer to actually create the mcs. I was trying to use the timer in conjunction with a for loop. Thanks again for your quick answer!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now