# Using variables as part of object names

**URL:** <https://forum.kirupa.com/t/using-variables-as-part-of-object-names/273148>\
**Category:** flash\
**Created:** [October 12, 2008, 5:46am UTC](https://forum.kirupa.com/t/using-variables-as-part-of-object-names/273148 "2008-10-12T05:46:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheCheshireCat](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@TheCheshireCat](https://forum.kirupa.com/u/TheCheshireCat)\
**Post date:** [October 12, 2008, 5:46am UTC](https://forum.kirupa.com/t/using-variables-as-part-of-object-names/273148/1 "2008-10-12T05:46:01Z")

</div>

Hey everyone!

I’m a new member of the forums, but I’ve been browsing this website for a while now, reading posts and tutorials,  
and I wanted to say that I really like it here. Everybody are very helpful and websites such as this one really make it  
easier to learn flash. (I like learning stuff by myself, I already managed to make myself a portfolio website thanks to such tutorials)

I need your help; I’m making a menu which has 5 dynamic texts instance-named buttontxt1, buttontxt2… buttontxt5.  
I’m using a code in order to take information from a .txt file and put it in these texts’ text fields.  
This worked fine, but instead of writing:

buttontxt1.text=e.target.data.ArtistName1;  
buttontxt2.text=e.target.data.ArtistName2;  
…  
buttontxt5.text=e.target.data.ArtistName5;

I wanted to make it more elegant, so I wrote:

for (var i:Number = 1; i \<= 5; i++){  
this[“buttontxt”+i].text=e.target.data.target[“ArtistName”+i];  
trace(“buttontxt”+i);  
}

However, theres a syntax error regarding —\> target[“ArtistName”+i];

Could you please tell me the right way to phrase this?

THANKS in advance!

Cat
