Step Down For Loop with Flash ActionScript 3 Code
In previous For Loop Flash ActionScript tutorials, we only use Step Up For Loops. Is it possible to use Step Down For Loop, i.e. the variable decrease with each loop? Yes. This Flash ActionScript tutorial shows how to do that.
Flash Tutorial Content:
Sometimes you may require the value of the variable decrease by any amount with each loop. The rule is of a Step Down For Loop is same as Step Up For Loop in Flash ActionScript. Instead of writing an expression increase the value of the variable with each loop (e.g. i++, i=i+2, etc..), we write an expression decrease the value of the variable with each loop (e.g. i--, i=i-2, etc..)
The complete Flash Movie is shown as above, you may try how it works before you start this Flash tutorial.
Flash ActionScript Codes:
//Set the multiline parameter of the Text Field to true
//The <br> tag creates a line break in the Text Field.
//Must set the text field to be a multiline Text Field to use this tag.
output_txt.multiline = true;
//Declare a string to the data
//Also assign an empty value to this string (myString)
var myString:String = "";
//Declare i as an integer
//Execute the For Loop Statement
//A For Loop requires three expressions:
//a variable i is set to an initial value - 5
//a conditional determines when the looping ends - when i >0
//an expression changes the value of the variable with each loop - i-- (decrease by one)
for (i = 5; i > 0; i--)
//Display the string to Text Field
output_txt.htmlText = myString;
Download Flash Source File:
For Loop is a very powerful statement. You should find at least one For Loop in any complicated program. This Flash ActionScript tutorial shows how to use a Step Down For Loop statement.