# Concatenate varName

**URL:** <https://forum.kirupa.com/t/concatenate-varname/17371>\
**Category:** flash\
**Created:** [April 4, 2003, 9:59am UTC](https://forum.kirupa.com/t/concatenate-varname/17371 "2003-04-04T09:59:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuie](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@stuie](https://forum.kirupa.com/u/stuie)\
**Post date:** [April 4, 2003, 9:59am UTC](https://forum.kirupa.com/t/concatenate-varname/17371/1 "2003-04-04T09:59:12Z")

</div>

I want to increment a variable name within a loop so that the values in the loaded vars are added dynamically.  
See below, inside setProperty() i want to add the value of i to the varNames siteX and siteY  
so siteX + i would now become siteX1, siteX2 etc  
// dummy coords to test  
var siteX1 = “264”;  
var siteY1 = “183”;  
var siteX2 = “206”;  
var siteY2 = “99”;  
//  
amount = 2;  
//  
while (amount\>0) {  
duplicateMovieClip (\_root.BaseSite, “NewSite”+i, i);  
// postion them using the passed co-Ords  
setProperty (“NewSite”+i, \_x, siteX+i);  
setProperty (“NewSite”+i, \_y, siteY+i);  
/:text = siteY+i;  
i = i+1;  
amount = amount-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 4, 2003, 12:06pm UTC](https://forum.kirupa.com/t/concatenate-varname/17371/2 "2003-04-04T12:06:17Z")

</div>

use eval() as in

setProperty (\<b\>eval(\</b\>“NewSite”+i\<b\>)\</b\>, \_x, \<b\>eval(\</b\>siteX+i\<b\>)\</b\>);

or try something like this

site = new Array([264, 183], [206, 99]);  
for (var i = 1; i \< site.length+1; i++) {  
var instanceName = “NewSite”.concat(i);  
with (\_root) {  
BaseSite.duplicateMovieClip(instanceName, i);  
with (eval(instanceName)) {  
\_x = site[i-1][0];  
\_y = site[i-1][1];  
}  
}  
}

Just drop in the coords you want as an array in the format [\_x,\_y] and the AS will duplicate BaseSite and assign the specified coords
