Step Up For Loop with Flash ActionScript 3 Code (2)
Sometimes you may require the value of the variable increase by more than one with each loop, i.e. n, n+2, n+4, n+6, etc... until the looping ends.
Flash Tutorial Content:
Although Step Up For Loop with increasement of 1 is most commonly used in a For Loop Statement with Flash ActionScript. Actually the value of the variable can be increased by any amount with each loop.
The complete Flash Movie is shown as above, you may try how it works before you start this Flash ActionScripttutorial.
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 - zero
//a conditional determines when the looping ends - when i < 5
//an expression changes the value of the variable with each loop - i=i+2 (increase by two)
for (i = 0; i < 5; i=i+2)
//Display the string to Text Field
output_txt.htmlText = myString;
Download Flash Source File:
Up to now, we only use Step Up For Loops in our Flash ActionScript tutorial. Is it possible to use Step Down For Loop, i.e. the variable decrease with each loop? Yes. The next Flash ActionScript tutorial will show how to do that.