# addEventListener in a for loop and value keeps coming back the same for the function

**URL:** <https://forum.kirupa.com/t/addeventlistener-in-a-for-loop-and-value-keeps-coming-back-the-same-for-the-function/322724>\
**Category:** flash\
**Created:** [May 31, 2011, 9:42pm UTC](https://forum.kirupa.com/t/addeventlistener-in-a-for-loop-and-value-keeps-coming-back-the-same-for-the-function/322724 "2011-05-31T21:42:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SammyTheBear](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@SammyTheBear](https://forum.kirupa.com/u/SammyTheBear)\
**Post date:** [May 31, 2011, 9:42pm UTC](https://forum.kirupa.com/t/addeventlistener-in-a-for-loop-and-value-keeps-coming-back-the-same-for-the-function/322724/1 "2011-05-31T21:42:29Z")

</div>

This code keeps coming back with the same value for i when the button is clicked. It is looping through but only the last value gets passed. Any help would be great.

for(var i:uint=0; i\<10; i++)  
{  
this[“Nav”+(i+1)].addEventListener(MouseEvent.CLICK, runNav);  
function runNav(event:Event):void  
{  
dispatchEvent(new changeNav(i+1))  
}  
}

Cheers!
