Pass Parameters to Event Listeners?

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:


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


t.addEventListener(MouseEvent.MOUSE_DOWN, buttonClicked);

to


t.addEventListener(MySpecialMouseEvent.MOUSE_DOWN, buttonClicked);

would help anything.