# Accessing dyanamically named MCs

**URL:** <https://forum.kirupa.com/t/accessing-dyanamically-named-mcs/299785>\
**Category:** Uncategorized\
**Created:** [November 10, 2009, 11:22pm UTC](https://forum.kirupa.com/t/accessing-dyanamically-named-mcs/299785 "2009-11-10T23:22:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayJunk](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@JayJunk](https://forum.kirupa.com/u/JayJunk)\
**Post date:** [November 10, 2009, 11:22pm UTC](https://forum.kirupa.com/t/accessing-dyanamically-named-mcs/299785/1 "2009-11-10T23:22:50Z")

</div>

Trying to get from AS2 to AS3 and the simpliest things are taking too long. Maybe someone can help me please.

I have some movieclips on the main timeline named…  
btnSm1\_mc  
btnSm2\_mc  
btnSm3\_mc  
etc…

They are physically placed on the stage, not coded.

When I click on one I want to move that MC to frame 2.  
And move the last one clicked back to frame 1.

For each MC I have an onClick handler like this…  
btnSm1\_mc.addEventListener(MouseEvent.CLICK, onClickHandler);

The onClickHandler works fine.

I have this var outside the onClickHandler function…

var currentNumString:String = “1”;

I have my onClickHandler function like this…

function onClickHandler(e:MouseEvent) {

// need to grab the number of the MC that was clicked  
// i.e. if I click on btnSm7\_mc, then newNumString is “7”

var newNumString:String;  
newNumString = e.target.name.substr(5,1);

// THIS IS THE PART I DON"T GET…  
// I used to use this AS2 code to access dynamically named MCs…  
// this doesn’t work with AS3 so this is the part i need help with the AS3 code…

this[“btnSm”+currentNumString+"\_mc"].gotoAndStop(1);  
this[“btnSm”+newNumString+"\_mc"].gotoAndStop(2);

// set currentNumString to newNumString  
currentNumString = newNumString;

}

So the question is how do you access MCs that are on the stage?

I have tried everything I can think of…  
stuff like…

DisplayObjectContainer(getChildByName(“btnSm”+newNumString+"\_mc")).gotoAndStop(2);

this.getChildByName(“btnSm”+newNumString+"\_mc").gotoAndStop(2);

MovieClip(“btnSm”+newNumString+"\_mc").gotoAndStop(2);

I can access the MC if I just reference it like…

btnSm4\_mc.gotoAndStop(2);

but I need it to be able to do it like this…

this[“btnSm”+newNumString+"\_mc"].gotoAndStop(2);

Any one that can help, I would be very grateful.

Thanks.
