# Loop through class object creation?

**URL:** <https://forum.kirupa.com/t/loop-through-class-object-creation/276794>\
**Category:** flash\
**Created:** [December 3, 2008, 6:24pm UTC](https://forum.kirupa.com/t/loop-through-class-object-creation/276794 "2008-12-03T18:24:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntifreezeDesig](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@AntifreezeDesig](https://forum.kirupa.com/u/AntifreezeDesig)\
**Post date:** [December 3, 2008, 6:24pm UTC](https://forum.kirupa.com/t/loop-through-class-object-creation/276794/1 "2008-12-03T18:24:46Z")

</div>

Why can’t I loop through a class object creation? I’m trying to create multiple instances of a point on a map, but it won’t let me “build” my name. When I do it without the unique names, all is well until I try to set up listeners, which all seem to point only to the last one created. I have a feeling I’m trying to fit 3.0 into my 2.0 mindset. Any help? Thx.  
function addLocations() {  
//In my library, I have a MC class “Location”, which has the basic art for each “location” being put on a map.  
for (var i:Number =0; i\<21; i++) {  
var which = “Loc”+i;  
which=new Location();  
addChild(which);  
which.addEventListener(MouseEvent.MOUSE\_UP, openStats);  
}  
}  
function openStats(event:MouseEvent) {  
//here, I’d like to add a Mc or class to the stage, and customize it for the location pressed  
//such as add a title, pull some text, etc. specific to the location  
}

(Sorry about the bad formatting. Firefox is bugging on me)
