# Loading variables in a loop

**URL:** <https://forum.kirupa.com/t/loading-variables-in-a-loop/2731>\
**Category:** Uncategorized\
**Created:** [April 26, 2002, 9:35am UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731 "2002-04-26T09:35:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 9:35am UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/1 "2002-04-26T09:35:15Z")

</div>

Hi!\r\rI’ve a .txt-file containing variables. The variables are structured like this:\r\raaa\_301, bbb\_301, ccc\_301\raaa\_302, bbb\_302, ccc\_302\r…\raaa\_325, bbb\_325, ccc\_325\r\rTo use them in Flash I have to read them from the .txt-file and assign them. This could look like this:\r\ronClipEvent (data) {\r&nbsp &nbsp &nbsp &nbsp \_root.aaa\_301 = aaa\_301;\r&nbsp &nbsp &nbsp &nbsp \_root.bbb\_301 = bbb\_301;\r&nbsp &nbsp &nbsp &nbsp \_root.ccc\_301 = ccc\_301;\r&nbsp &nbsp &nbsp &nbsp \_root.aaa\_302 = aaa\_302;\r&nbsp &nbsp &nbsp &nbsp \_root.bbb\_302 = bbb\_302;\r&nbsp &nbsp &nbsp &nbsp \_root.ccc\_302 = ccc\_302;\r&nbsp &nbsp &nbsp &nbsp …\r&nbsp &nbsp &nbsp &nbsp \_root.aaa\_325 = aaa\_325;\r&nbsp &nbsp &nbsp &nbsp \_root.bbb\_325 = bbb\_325;\r&nbsp &nbsp &nbsp &nbsp \_root.ccc\_325 = ccc\_325;\r}\r\rIs it possible to use a loop instead of write 301, 302, …325?\r\rI thought of:\r\ronClipEvent (data) {\r for (i=301; i=325; i++){\r&nbsp &nbsp &nbsp &nbsp \_root.aaa\_i = aaa\_i;\r&nbsp &nbsp &nbsp &nbsp \_root.bbb\_i = bbb\_i;\r&nbsp &nbsp &nbsp &nbsp \_root.ccc\_i = ccc\_i;\r }\r}\r\rAny idea how the code could look like?\r\rMany thanks,\r\rHartwig

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 10:13am UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/2 "2002-04-26T10:13:47Z")

</div>

Are you sure that you’re txt is writen correctly?\r\rIt should look something like\r\r&aaa\_301=something&bbb\_301=something&ccc\_301=something&aaa\_302=something&bbb\_302=something&ccc\_302=something&

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 11:51am UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/3 "2002-04-26T11:51:06Z")

</div>

Hi!\r\rYes of course. The .txt-file is written correctly. I just wanted to demonstrate the structure of the variables. But how could the for-loop look like?\r\rHartwig

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 12:04pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/4 "2002-04-26T12:04:14Z")

</div>

i think that code looks right…maybe create 3 for loops one for aaa, one for bbb, and one for ccc?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 12:23pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/5 "2002-04-26T12:23:12Z")

</div>

No no no no.

```auto
 onClipEvent (data) {\r\rfor (i=301; i=325; i++){\r\r root["aaa_"+i] = this["aaa_"+i] ; // no _ in front of root.\r\r root["bbb_"+i] = this["bbb_"+i] ;\r\r }\r\r}

```

But I don’t see why you need to put them in the root.\r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 12:27pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/6 "2002-04-26T12:27:07Z")

</div>

writing this\r\ronClipEvent (data) {\r&nbsp &nbsp &nbsp &nbsp for (i=301; i\<326; i++) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp set (“_root.name_”+i, “aaa\_”+i);\r\rthe result ist that the variables get the value aaa\_301, aaa\_302, … and not the value that is assigned in the txt-file.\r\rAre the " " on a wrong position?\r\rHartwig

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 12:36pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/7 "2002-04-26T12:36:17Z")

</div>

Hi!\r\rmaking the \_ infront of root, everything works fine\r\rTHX a lot\r\rHartwig

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 1:53pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/8 "2002-04-26T13:53:34Z")

</div>

Just in case (I’m not saying this to you, Hart), it’s usually not a good idea to put an equality as a condition of a for loop (here it’s i=325). i\<=325 or i\<326.\r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 2:00pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/9 "2002-04-26T14:00:32Z")

</div>

What did I write ?? Of course there’s a \_ in front of root. !!\r\rpom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 26, 2002, 3:38pm UTC](https://forum.kirupa.com/t/loading-variables-in-a-loop/2731/10 "2002-04-26T15:38:13Z")

</div>

Yes, you’re right Pom. (i=301; i\<326; i++) is better, because = causes the system to get very slow
