0

im very new to as3 so i would appreciate any help. Im trying to make a counter only using the command "for". im counting on this from 1 to 1000 in steps of 20. the next step i want to make is to display on the output tab i already know i can make it with "trace();", but i also want this to be displayed on the main .swf window, im trying using a dynamic text-field which i named "dyna"

The problem is that, it is only displaying the last number. "1000" or changing very fast that i barely notice, and the last one remains.

var i:int;
for (i = 1; i < 1001; i+=20)
{
trace(i);
//dyna is the name of my dynamic textfiled
dyna.text = i.toString();
//dinamico.text = String(i);
}

-Is there any way to record all the numbers on my dynamic textbox, something like [1,20,40,60,....] horizontally or vertically.

-Or maybe someway to run this from a button step by step. like [click, 20; click, 40; click 60.....]

Thanks in advance

2 Answers2

0
var i:int;
var str:String="1";

for (i = 20; i < 1001; i+=20)
{
  str=str+","+i;
}
dyna.autoSize = TextFieldAutoSize.LEFT;
dyna.text=str;

Output 1,20,40,60,80,100,120,140,160...

Hope it helps

g89n7man
  • 59
  • 1
  • 1
  • 6
0

To run this from the button step by step you need a button, a listener attached to the button, a counter available to both button and text field, and a bit of code. The button has to be somewhere on the stage or in your asset, and named somehow, so you can address it by the name. Here it's named yourButton:

var counter:int=0;
yourButton.addEventListener(MouseEvent.CLICK,updateDyna);
function updateDyna(e:MouseEvent):void {
    counter+=20;
    if (counter>1000) counter=1000;
    dyna.text=counter.toString();
}

Here you are, click - 20, click - 40, etc., up to 1000.

Vesper
  • 18,599
  • 6
  • 39
  • 61
  • nice thanks, it helped me a lot. it worked nice, im just trying to run this method from a "for" form for (i = 1; i < 1001; i+=20) – user2215959 Mar 27 '13 at 21:58
  • Count a call to click listener as a single iteration of your cycle, all preparations as what you are writing in brackets within `for(...)` construction. Also, your "for" cycle will not stop to display you the previous value of the counter, so either use this, or use `dyna.appendText()` to concatenate old text with anything new. – Vesper Mar 28 '13 at 03:35