tags:

views:

61

answers:

1

i have an application in which i have around 100 textinputs all are numbers

i want to simplify the addition ie. any other way than saying txt1.text+txt2.text.....

that would increase my code a lot

is it possible to have (n+=txt*.text) or some thing like that

any help would be appreciated have to get the application done in two days thank you

+1  A: 

If txt1, txt2 etc are public properties of the class representing this, you can use the following code to get the sum of the numbers in the text inputs.

var n:Number = 0;
for(i = 1; i <= total; i++)
  n += Number(this["txt" + i].text);

To get a concatenated string:

var s:String = "";
for(i = 1; i <= total; i++)
  s += this["txt" + i].text;

If the text inputs are properties of a different class, use the instance name of the object instead of this. For example:

instanceName["txt" + i].text;

Another solution that is more clean is to store them in an array and loop through them. But that might require changes in other parts of your code.

Amarghosh