# Need help: acces multiple elements dynamically by a for() problem (AS != JS)

**URL:** https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556
**Category:** Uncategorized
**Created:** [February 10, 2004, 11:19am UTC](https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556 "2004-02-10T11:19:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_4\_Cologne](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Alex\_4\_Cologne](https://forum.kirupa.com/u/Alex_4_Cologne)
#### Post date: [February 10, 2004, 11:19am UTC](https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556/1 "2004-02-10T11:19:32Z")

</div>

I wanna acces multiple elements onEnterFrame by a for()

I just dunno how to. barXX\_mc cannot be a var like in JavaScript (var barXX\_mc = “bar0”+i+"\_mc"). I am new to Flash and wonder how to do this :h:

Can somebody help me? If you need the \*.fla contact me by alexander(at)[dom.de](http://dom.de)

regards  
Alex

```php
/*	for(i = 0; i < bars; i++) {
		barXX_mc = ; // <-- ??? = "bar0"+i+"_mc" does not work, = bar01_mc is static *erks*
		barXX_mc._x = space + Math.sin(rad + (0.5 + i / (bars - 1)) * Math.PI) * amp;
	}*/

// The following should be replaced by the for() above
	
	bar00_mc._x = space + Math.sin(rad + 0.5 * Math.PI) * amp;
	bar01_mc._x = space + Math.sin(rad + (0.5 + 1 / (bars - 1)) * Math.PI) * amp;
	bar02_mc._x = space + Math.sin(rad + (0.5 + 2 / (bars - 1)) * Math.PI) * amp;
	bar03_mc._x = space + Math.sin(rad + (0.5 + 3 / (bars - 1)) * Math.PI) * amp;
	bar04_mc._x = space + Math.sin(rad + (0.5 + 4 / (bars - 1)) * Math.PI) * amp;
	bar05_mc._x = space + Math.sin(rad + (0.5 + 5 / (bars - 1)) * Math.PI) * amp;
	bar06_mc._x = space + Math.sin(rad + (0.5 + 6 / (bars - 1)) * Math.PI) * amp;
	bar07_mc._x = space + Math.sin(rad + (0.5 + 7 / (bars - 1)) * Math.PI) * amp;
	bar08_mc._x = space + Math.sin(rad + (0.5 + 8 / (bars - 1)) * Math.PI) * amp;
	bar09_mc._x = space + Math.sin(rad + (0.5 + 9 / (bars - 1)) * Math.PI) * amp;
	bar10_mc._x = space + Math.sin(rad + (0.5 + 10 / (bars - 1)) * Math.PI) * amp;
	bar11_mc._x = space + Math.sin(rad + 1.5 * Math.PI) * amp;

```

---

<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: [February 10, 2004, 1:07pm UTC](https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556/2 "2004-02-10T13:07:35Z")

</div>

Hi, the problem is that that the value of your variable is a string.

Providing that instances of your objectc (symbol) exist in the timeline you’re refering to simply make flash evaluate the string on your variable.:

[AS]  
for (i=0; i\<bars; i++) {  
if (i\<10) {  
var num =“0”+i;  
} else {  
var num = i;  
}  
var barXX\_mc = eval(“this.bar”+num+"\_mc");  
barXX\_mc.\_x = space+Math.sin(rad+(0.5+i/(bars-1))\*Math.PI)\*amp;  
}

[/AS]

SHO

---

<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: [February 10, 2004, 1:29pm UTC](https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556/3 "2004-02-10T13:29:59Z")

</div>

[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082)

---

<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: [February 10, 2004, 2:27pm UTC](https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556/4 "2004-02-10T14:27:46Z")

</div>

thx eki and seno!

---

<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: [February 11, 2004, 11:19am UTC](https://forum.kirupa.com/t/need-help-acces-multiple-elements-dynamically-by-a-for-problem-as-js/42556/5 "2004-02-11T11:19:49Z")

</div>

Any time :}
