Loops: Create a "for loop" in AS3

Create a button movieclip on your stage.
Give it an instance name of bStart.

Create an input text box on your stage.
Give it an instance name of itSteps.

Create a dynamic text box on your stage.
Give it an instance name of tMessages.

Actionscript:

bStart.addEventListener(MouseEvent.CLICK, fLoop);

itSteps.restrict = "0-9";
itSteps.maxChars = 3;

function fLoop(event:MouseEvent):void {
tMessages.text="";
var vString:String = itSteps.text;
var vExample:Number = Number(vString);
for (var i:Number=0; i < vExample; i++) { tMessages.appendText([i]+", "); } }

Example:

Get Adobe Flash player

Leave a Reply