# Dynamically creating variables (variable names)?

**URL:** <https://forum.kirupa.com/t/dynamically-creating-variables-variable-names/163055>\
**Category:** flash\
**Created:** [September 19, 2005, 12:54pm UTC](https://forum.kirupa.com/t/dynamically-creating-variables-variable-names/163055 "2005-09-19T12:54:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danko](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Danko](https://forum.kirupa.com/u/Danko)\
**Post date:** [September 19, 2005, 12:54pm UTC](https://forum.kirupa.com/t/dynamically-creating-variables-variable-names/163055/1 "2005-09-19T12:54:44Z")

</div>

Does anyone know how to do this in Flash? I’d like to dynamically create vars (var names) in a loop, like this:

```auto
var1 = 1;
var2 = 2;
var3 = 3;
...

```

The problem is that this doesn’t pass (because left side of the assigment has to be a property):

```auto
eval("_root."+myKey) = myValue;

```

This code doesn’t work well, also:

```auto
_root[myKey] = myValue;

```

I succedded in putting name/values pairs into an Array:

```auto
element[myVar] = myValue;

```

But this is not good for a given purpose, I’d rather have variables in \_root.
