Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

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.

Please update flash player to view this Flash ActionScript tutorial!

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
var i:int;

 

//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)
{

myString = myString + "The value of i is: " + i + "<BR>";

}

 

//Display the string to Text Field
output_txt.htmlText = myString;

Download Flash Source File:

Flash Source File for-loop-2.fla

Remarks:

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.