A
A
Alexander Sharomet2014-02-26 17:30:55
Programming
Alexander Sharomet, 2014-02-26 17:30:55

How to add a number to the name of an object in Actionscript 3.0?

Hello.

for(var i=1;i<10;i++){
this.txt[i].text=Math.round(Math.random()*10);
}

this.txt[i] is the name of the object but it is not added in the loop.
in the end it should look like this, but it doesn't work(
this.txt1
this.txt2
this.txt3
...
How can I fix this? Thanks.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
maxaon, 2014-02-26
@sharomet

Create the name dynamically, something like this:
this["txt"+i].text=Math.round(Math.random()*10);

F
Fat Lorrie, 2014-02-26
@Free_ze

Of course, I'm not strong in actionscript, but maybe it's worth not replacing the text, but appending it?...

A
Alexander N++, 2014-04-12
@sanchezzzhak

Math.round returns Number
Since as3 is typed, you should always cast the data to the correct types.
from number to line

var a:Number = Math.round(Math.random()*10);
a.toString() или String(a);

from string to number also
Number('123');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question