# Referencing instances of an object - newbie

**URL:** <https://forum.kirupa.com/t/referencing-instances-of-an-object-newbie/289571>\
**Category:** flash\
**Created:** [June 2, 2009, 1:25am UTC](https://forum.kirupa.com/t/referencing-instances-of-an-object-newbie/289571 "2009-06-02T01:25:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![melzee1975](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@melzee1975](https://forum.kirupa.com/u/melzee1975)\
**Post date:** [June 2, 2009, 1:25am UTC](https://forum.kirupa.com/t/referencing-instances-of-an-object-newbie/289571/1 "2009-06-02T01:25:48Z")

</div>

Hi,

Im having a problem getting my head around referencing instances of an object in AS3, can somebody please help?

I want to be able to build a navigation and reference each navigation item separately changing each instances properties depending on rollover actions etc.

I would have thought that once the name is assigned through the for loop that would stick, eg. the following code would create 3 vars called navItem, each with the name 0, 1, 2. But it seems if I trace the name outside of the for loop each is called 2. I think Im misunderstanding something really simple!

Please help.

Thanks!

public function buildNav():void {  
for (var i=0; i \<itemNum; i++){  
var navItem:NavItem = new NavItem ();  
navItem.name = i;  
navItem.x = (navItem.width+50)\*i;  
navItem.addEventListener(MouseEvent.MOUSE\_OVER, doSomething);  
navItem.count = i  
stage.addChild(navItem);  
if (navItem.count \< 1){  
navItem.gotoAndStop(2);  
}  
}  
function doSomething (e:MouseEvent):void {  
trace (navItem.name);  
}  
}
