4.
Select Frame 1 of the Timeline, and then type the following ActionScript in the
Actions panel:
var users_ds:mx.data.components.DataSet;
//
users_ds.addItem({name:"Irving", age:34});
users_ds.addItem({name:"Christopher", age:48});
users_ds.addItem({name:"Walter", age:23});
//
users_ds.first();
while (users_ds.hasNext()) {
trace("name:" + users_ds.currentItem["name"] + ", age:" +
users_ds.currentItem["age"]);
users_ds.next();
}
5.
Select Control > Test Movie to test the document.
The following information is displayed in the Output panel:
name:Irving, age:34
name:Christopher, age:48
name:Walter, age:23
For more information, see the
Reference.
About do..while loops
You can use the
do..while
However, the expression is evaluated at the bottom of the code block in a
checked after the code block executes), so the loop always runs at least one time. The
statements execute only if the condition evaluates to
The following code shows a simple example of a
though the condition is not met.
var i:Number = 5;
do {
trace(i);
i++;
} while (i < 5);
// Output: 5
When you use loops, you need to avoid writing infinite loops. If the condition in a
loop continuously evaluates to
do..while
warning or crashes Flash Player. Use a
want to loop. For more information on and examples of
ActionScript 2.0 Language Reference.
while statement
statement to create the same kind of loop as a
do..while
, you create an infinite loop that displays a
true
loop instead if you know how many times you
for
in the ActionScript 2.0 Language
.
true
loop that generates output even
do..while statement
loop.
while
loop (it's
do..while
, see the
About statements
161
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?
Questions and answers