# Dynamic variable name array

**URL:** <https://forum.kirupa.com/t/dynamic-variable-name-array/302632>\
**Category:** Uncategorized\
**Created:** [January 4, 2010, 4:16pm UTC](https://forum.kirupa.com/t/dynamic-variable-name-array/302632 "2010-01-04T16:16:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdulberg](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jdulberg](https://forum.kirupa.com/u/jdulberg)\
**Post date:** [January 4, 2010, 4:16pm UTC](https://forum.kirupa.com/t/dynamic-variable-name-array/302632/1 "2010-01-04T16:16:44Z")

</div>

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?

```auto

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
