# Single Event Hander for Multiple Buttons?

**URL:** https://forum.kirupa.com/t/single-event-hander-for-multiple-buttons/236389
**Category:** flash
**Created:** [August 20, 2007, 3:09pm UTC](https://forum.kirupa.com/t/single-event-hander-for-multiple-buttons/236389 "2007-08-20T15:09:54Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jstumbo](https://avatars.discourse-cdn.com/v4/letter/j/aca169/32.png) [@jstumbo](https://forum.kirupa.com/u/jstumbo)
#### Post date: [August 20, 2007, 3:09pm UTC](https://forum.kirupa.com/t/single-event-hander-for-multiple-buttons/236389/1 "2007-08-20T15:09:54Z")

</div>

I am new Flash and Actionscript. This is actually my first attempt at creating a website with it.

I have a mc that has 23 buttons (thumbnails) on it, and one larger picture(uiloader) in the middle. When you click on a button, it changes the source value of the uiloader to be equal to the file that the button is associated with, and changes a dynamic textfield below the picture to a description string.

It is my understanding that I need 23 event listeners, one for each button and then 23 event handlers, one for each event listener. This seems crazy to me. I have created it that way, and it works just fine, but what if I had 200 buttons, would I have to create 200 event handlers?

Is there a way to do something like the following:

```auto
 
function onPhotoClick(evt:MouseEvent,file:String,desc:String):void {
     Photo_ldr.source = file;
     Photo_txt.text = desc;
}
 
Photo1_btn.addEventListener(MouseEvent.CLICK,onPhotoClick("photo1.jpg","photo1 description");
 
Photo2_btn.addEventListener(MouseEvent.CLICK,onPhotoClick("photo2.jpg","photo2 description");

```

I know this does not work, but any suggestions, I am sure others are doing something like this. Also, I looked into creating cutom events, but then wouldnt I need to create 23 custom events, one for each button, and then still have the 23 event listeners.

Anyone have know of a simple flash that includes source to do something like this?

[Than](http://swedeco.thewoodflooroutlet.com)ks,  
Jim
