# How to reference to dynamically created sprites?

**URL:** <https://forum.kirupa.com/t/how-to-reference-to-dynamically-created-sprites/239913>\
**Category:** flash\
**Created:** [September 27, 2007, 6:58am UTC](https://forum.kirupa.com/t/how-to-reference-to-dynamically-created-sprites/239913 "2007-09-27T06:58:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sumo/32/1950_2.png) [@sumo](https://forum.kirupa.com/u/sumo)\
**Post date:** [September 27, 2007, 6:58am UTC](https://forum.kirupa.com/t/how-to-reference-to-dynamically-created-sprites/239913/1 "2007-09-27T06:58:30Z")

</div>

Hello.

I have a problem with creating dynamically some sprites that act as buttons and then referencing to them later on. Basically I just create three instances of my own buttonClass that has some rollOvers and outs. I use a for loop for that. Later on I want to change let’s say the second and third instances y coordinate. How do I reference to those instances? Here is my code:  
[AS]  
private function createMainButtons()  
{  
var btnTextArrayMain:Array = new Array(“first”, “second”, “third”);  
for(var i:int = 0; i \< 3; i++)  
{  
btn = new buttonClass();  
btn.name = “mainBtn” + String(i);  
btn.txt\_mc.teksti.text = btnTextArrayMain\*;  
btn.addEventListener(MouseEvent.CLICK, bclick);  
btn.x = 60;  
btn.y = 150 + i \* 20;  
addChild(btn);  
}  
}  
[/AS]  
I tried to use mainBtn1.y = 100; as I set the name property for each btn “mainBtn” + String(i) but it seems that I can’t use the name property for referencing to that instance.

Sumo
