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

pause script in while loop for 2 seconds

Guest
Dec 18, 2009 Dec 18, 2009

Hello,

I am a novice flash programmer, and i recently stumbled upon the following problem,

I got the following code ;

stop();
import com.greensock.*;
import com.greensock.easing.*;

var loop1:Number = 0;
while (loop1 < 10){
     var line_1:MovieClip = new MovieClip();
     this.addChild(line_1);
     var line_1_x = randomNumber(0, 550);
     line_1.graphics.lineStyle(randomNumber(2,8), Math.random()*0xBBD9F7);
     line_1.graphics.moveTo(line_1_x,0); ///begin tekenen
     line_1.graphics.lineTo(line_1_x, 600);
     TweenLite.to(line_1, 10, {x:randomNumber(0, 550), alpha:0});
     stop();
     theTimer.start();
     //wait 2 seconds here
     loop1++;
}

How do i do that?

TOPICS
ActionScript
670
Translate
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

correct answers 1 Correct answer

LEGEND , Dec 18, 2009 Dec 18, 2009

There is no delaying a while/for/etc loop.  If you want something to loop with a delay you have to manufacture your own loop.  Create the functionality as a set of functions that you call as long as your counter is still below the limit.

var counter:int = 0;

function doStuff():void {

     // stuff

    counter++;

     if(counter < 10){

          call a timer to delay call to continueFunction for 2 seconds

     }

}

function continueFunction(evt:TimerEvent):void {

     doStuff();

}

doStuff(); // kick things of

...
Translate
LEGEND ,
Dec 18, 2009 Dec 18, 2009
LATEST

There is no delaying a while/for/etc loop.  If you want something to loop with a delay you have to manufacture your own loop.  Create the functionality as a set of functions that you call as long as your counter is still below the limit.

var counter:int = 0;

function doStuff():void {

     // stuff

    counter++;

     if(counter < 10){

          call a timer to delay call to continueFunction for 2 seconds

     }

}

function continueFunction(evt:TimerEvent):void {

     doStuff();

}

doStuff(); // kick things off

Translate
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