# Pass Parameters to Event Listeners?

**URL:** <https://forum.kirupa.com/t/pass-parameters-to-event-listeners/295707>\
**Category:** Uncategorized\
**Created:** [September 3, 2009, 6:46am UTC](https://forum.kirupa.com/t/pass-parameters-to-event-listeners/295707 "2009-09-03T06:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeerOclock](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@BeerOclock](https://forum.kirupa.com/u/BeerOclock)\
**Post date:** [September 3, 2009, 6:46am UTC](https://forum.kirupa.com/t/pass-parameters-to-event-listeners/295707/1 "2009-09-03T06:46:02Z")

</div>

I know. This question gets asked a lot. And it usually gets the same answer: Use custom events. Well I’m sorry but after an hour of Googling, I havnt found a single useful example of ‘using custom events’ that helps me. I will post my specific problem and I hope someone can show me exactly where ‘custom events’ come in.

Suppose I want to create a bunch of buttons using a loop. But I want each button to do something different. Suppose the buttons are numbered and I simply want each button to print out its unique number when clicked. Heres what I have so far:

```auto

var t:CTextField;
for (var i:int = 1; i <= 100; i++) {								
 t = new TextField();
 t.text = "button " + i;
 t.y = 20 * i;
 t.height = 20;
 t.addEventListener(MouseEvent.MOUSE_DOWN, buttonClicked);
 addChild(t);	
}

private function buttonClicked(e:MouseEvent):void {
 trace ("button " + ??? + " was clicked");
}

```

Ive tried many different things to get this to work, but none of them worked so I wont bother posting them all. At best, I got it so every single button traced “button 100 was clicked”. I sort of understand why that happened, but I dont know how to make it work properly.

Once again, all I could find was people saying “use custom events”, but I think I need a lot more details than that. For example, I dont see how changing

```auto

t.addEventListener(MouseEvent.MOUSE_DOWN, buttonClicked);

```

to

```auto

t.addEventListener(MySpecialMouseEvent.MOUSE_DOWN, buttonClicked);

```

would help anything.
