Dynamic variable name array

Hello,

I’m new to AS3 and converting some old AS2 code that uses dynamic variable names. I know that you cannot do this in AS3 - how would I accomplish the following in AS3?


for (i = 1; i < (k+1); i++) {
   AI* = setVals(k, (k*2));
}
for (i = 0; i < (k-1); i++) {
   p = _root["AI"+i]**;
   ps* = p;
}

There are quite a few instances in my existing code that use these dynamic variables. I’ve seen some posts suggesting to use arrays - how would I set up an array to reference the variables in the same fashion? Is an array the best way?

Any suggestions would be great, thanks!
Jason