# Loop on Variable Name

**URL:** <https://forum.kirupa.com/t/loop-on-variable-name/329256>\
**Category:** flash\
**Created:** [August 6, 2012, 11:34pm UTC](https://forum.kirupa.com/t/loop-on-variable-name/329256 "2012-08-06T23:34:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rustythread](https://avatars.discourse-cdn.com/v4/letter/r/b3f665/32.png) [@rustythread](https://forum.kirupa.com/u/rustythread)\
**Post date:** [August 6, 2012, 11:34pm UTC](https://forum.kirupa.com/t/loop-on-variable-name/329256/1 "2012-08-06T23:34:19Z")

</div>

I have many buttons on my stage about 45 for interaction. The idea is when you press a button it goes to frame2 of its movie clip and lights up.

I then have a reset button which reverts all buttons to the frame 1 state.

I End up having so many lines of code and i believe it could be shortened with a for loop. This is what I have for my Reset code.

e.g.

MovieClip(Btn1).gotoAndStop(“1”);  
MovieClip(Btn2).gotoAndStop(“1”);  
MovieClip(Btn3).gotoAndStop(“1”);  
MovieClip(Btn4).gotoAndStop(“1”);  
MovieClip(Btn5).gotoAndStop(“1”);  
MovieClip(Btn6).gotoAndStop(“1”);  
-Theres about 45 of these.

Is it possible to change select my variable with a for loop.

e.g.

for (var i:Number = 0; i\<46, i++)  
{  
MovieClip(Btn"i").gotoAndStop(“1”);  
}

Any help would be great thanks
