Do While Statement
Flash CS4 ActionScript 3.0 Tutorial
How to Assign and Check Data with Flash ActionScript
Loops are handy pieces of code if you want to fill an array, add several Loaders or check several pieces of data. In other words, loops work great to populate an array, movie clip or the stage. Once a loop starts, it consumes the processor resources. It is important that you don't create an endless loop that you can't escape.
Loops come in multiple varieties. Common loops include For, Do While and While statements. Note that For statements and Do While statements accomplish the same task. The Do While statement makes the test at the end of the loop and the For statement test is at the beginning of the loop.
Open a new Flash document and name the default layer Actions.
Open the ActionScript panel for the only keyframe in the Actions layer by Option double-clicking (PC - Alt double-clicking) the keyframe.
Copy/Paste the following code in the ActionScript Panel:
var cube01:Shape=new Shape;
Click the Auto Format button to format the code
Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). Five rounded rectangles appear on the stage.
Dissecting the Code
The first line of the code at Step Three establishes a new variable named boxCount and sets it's value to one.
The do statement specifies all the things that need to be done. A new Shape variable is introduced named cube01. Lines four through seven define the rounded rectangle shape.
The addChild() statement adds the object to the stage and the next line distributes the multiple objects across the stage.
The final line in the curly brackets increments the boxCount variable by one for each pass through the statement.
The final line is a while statement. As long as the boxCount variable stays below six, the Do portion of the statement continues to run.