# Dynamic variable reference

**URL:** https://forum.kirupa.com/t/dynamic-variable-reference/213409
**Category:** flash
**Created:** [January 19, 2007, 10:09am UTC](https://forum.kirupa.com/t/dynamic-variable-reference/213409 "2007-01-19T10:09:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hommer](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@Hommer](https://forum.kirupa.com/u/Hommer)
#### Post date: [January 19, 2007, 10:09am UTC](https://forum.kirupa.com/t/dynamic-variable-reference/213409/1 "2007-01-19T10:09:33Z")

</div>

I have some variables called  
\_root.name1  
\_root.name2  
\_root.name3  
\_root.name4

I want to initiate the three variables by refering to them dynamically.  
Here is my script, which is not working (The variables never get any value):

```auto
for (var i = 0; i<7; i++) {
     if (i%2 == 0) {
          var temp = "name"+((i+2)/2);
          _root[temp] = my_array*;
     }
}

```

How do I refer to the variables dynamically?
