# Duplicating addEventListener functionality with a loop?

**URL:** <https://forum.kirupa.com/t/duplicating-addeventlistener-functionality-with-a-loop/290755>\
**Category:** flash\
**Created:** [June 19, 2009, 5:31am UTC](https://forum.kirupa.com/t/duplicating-addeventlistener-functionality-with-a-loop/290755 "2009-06-19T05:31:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BadBadNeil](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@BadBadNeil](https://forum.kirupa.com/u/BadBadNeil)\
**Post date:** [June 19, 2009, 5:31am UTC](https://forum.kirupa.com/t/duplicating-addeventlistener-functionality-with-a-loop/290755/1 "2009-06-19T05:31:57Z")

</div>

Hello,  
I have 14 movie clips on the stage, each of which has it’s own on and off mode and each goes to a separate URL.

I would like to use loops to consolidate the code however I am having trouble with the handler.

So far I am using the code below but the question is how do you give each button it’s own functionality since the handler is the same?

Thanks for the help, I’m lost and out of ideas.

```auto

for (var i:uint = 1; i < 3; i++) {
	this["lexus"+i].addEventListener(MouseEvent.MOUSE_OVER, manageMouseOver);
	this["lexus"+i].addEventListener(MouseEvent.ROLL_OUT, manageMouseOut);
}

	function manageMouseOver(e:MouseEvent):void{
	  event.currentTarget.gotoAndPlay("on");
	}
	 
	function manageMouseOut(e:MouseEvent):void{
	  event.currentTarget.gotoAndPlay("off");
	}

```
