# How do you concatenate variables onto movieclip names

**URL:** https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724
**Category:** Uncategorized
**Created:** [June 29, 2008, 3:41pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724 "2008-06-29T15:41:48Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)
#### Post date: [June 29, 2008, 3:41pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/1 "2008-06-29T15:41:48Z")

</div>

var c = mainSubThumbs.SubThumbsHolder[materialType].subthumb\_mc[id]

what i have obviously doesnt work. materialType and id are my variables that I want to be added onto these mc instances…

---

<div class="post-metadata">

### Author: ![ajcates](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ajcates/32/2435_2.png) [@ajcates](https://forum.kirupa.com/u/ajcates)
#### Post date: [June 29, 2008, 4:51pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/2 "2008-06-29T16:51:47Z")

</div>

I would place these movieclips in an array so you can access them like this:

```auto

var myArray = new Array(new Movieclip(), new Movieclip());
trace(myArray[1].x);

```

Also this way allows for you to easily loop thur the arrays.

---

<div class="post-metadata">

### Author: ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)
#### Post date: [June 29, 2008, 5:36pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/3 "2008-06-29T17:36:53Z")

</div>

var c = mainSubThumbs.subThumbsHolder[materialType][“subthumb\_mc”][id]

should work fine.

---

<div class="post-metadata">

### Author: ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)
#### Post date: [June 29, 2008, 8:30pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/4 "2008-06-29T20:30:07Z")

</div>

[QUOTE=sekasi;2350992]var c = mainSubThumbs.subThumbsHolder[materialType][“subthumb\_mc”][id]

should work fine.[/QUOTE]

I tried your way. and this way:  
\_global.c = mainSubThumbs.[“SubThumbsHolder”][materialType].[“subthumb\_mc”][id];

Im still getting undefined.

what I want is it to be for example mainSubThumbs.SubThumbsHolder0.subthumb\_mc5;  
Which is the location of of the thumbnail that was clicked.

---

<div class="post-metadata">

### Author: ![scallywag](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@scallywag](https://forum.kirupa.com/u/scallywag)
#### Post date: [June 29, 2008, 9:08pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/5 "2008-06-29T21:08:22Z")

</div>

try

ActionScript Code:  
[LEFT][COLOR=#000000] **var** [/COLOR] c = mainSubThumbs[COLOR=#000000][[/COLOR][COLOR=#ff0000]“SubThumbsHolder”[/COLOR]+materialtype[COLOR=#000000]][/COLOR][COLOR=#000000][[/COLOR][COLOR=#ff0000]“subthumb\_mc”[/COLOR]+id[COLOR=#000000]][/COLOR];  
[/LEFT]

---

<div class="post-metadata">

### Author: ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)
#### Post date: [June 29, 2008, 9:22pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/6 "2008-06-29T21:22:21Z")

</div>

no this doesnt work either.

---

<div class="post-metadata">

### Author: ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)
#### Post date: [June 30, 2008, 8:14am UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/7 "2008-06-30T08:14:10Z")

</div>

> 

createEmptyMovieClip([“subthumb\_mc”+id],1)  
cheatvariable = [“subthumb\_mc”+id]  
mainSubThumbs.createEmptyMovieClip(“SubThumbsHolder”+materialType].cheatvariable,1  
daft statement but you have to create a so called MC, you can’t declare movie clips like a variable…

---

<div class="post-metadata">

### Author: ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)
#### Post date: [June 30, 2008, 5:41pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/8 "2008-06-30T17:41:46Z")

</div>

ok thanks.

but im trying assign the location of the mc’s to a variable. the movieclips already exist, so wouldnt creating the mc’s again overwite the existing ones?

Maybe there is a different method of doing this?

---

<div class="post-metadata">

### Author: ![scallywag](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@scallywag](https://forum.kirupa.com/u/scallywag)
#### Post date: [June 30, 2008, 9:12pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/9 "2008-06-30T21:12:29Z")

</div>

[quote=geestring;2351427]ok thanks.

but im trying assign the location of the mc’s to a variable. the movieclips already exist, so wouldnt creating the mc’s again overwite the existing ones?

Maybe there is a different method of doing this?[/quote]  
The script i gave you does work, i have enclosed example.

Maybe you are trying to reference clips before they exist??

---

<div class="post-metadata">

### Author: ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)
#### Post date: [July 2, 2008, 12:28pm UTC](https://forum.kirupa.com/t/how-do-you-concatenate-variables-onto-movieclip-names/264724/10 "2008-07-02T12:28:46Z")

</div>

sorry it does indeed work. Another overlooked error somewhere else.

Thanks
