
Copy link to clipboard
Copied
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?
1 Correct answer
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
...Copy link to clipboard
Copied
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

