# Passing parameters with addEventListener?

**URL:** <https://forum.kirupa.com/t/passing-parameters-with-addeventlistener/283229>\
**Category:** Uncategorized\
**Created:** [March 3, 2009, 10:30pm UTC](https://forum.kirupa.com/t/passing-parameters-with-addeventlistener/283229 "2009-03-03T22:30:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpearson311](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jpearson311](https://forum.kirupa.com/u/jpearson311)\
**Post date:** [March 3, 2009, 10:30pm UTC](https://forum.kirupa.com/t/passing-parameters-with-addeventlistener/283229/1 "2009-03-03T22:30:30Z")

</div>

So I have an MC that has 6 labels and 6 buttons all with different names. When you click on a button, it needs to direct you to it’s appropriate frame label in the MC. Now, since AS 3.0 has done away with inline functions, how the heck do I code it so I don’t have a function with a bunch of if statements inside of it in addition to all of my eventListeners that I have to add to each of my buttons?

In AS 2.0, I would have done it like so:

```auto

function movePlayhead(whichOne:String):Void{
     this.gotoAndStop(whichOne);
}

button1_mc.onRelease = function():Void{
     movePlayhead("label1");
};

button2_mc.onRelease = function():Void{
     movePlayhead("label2");
};

ETC...

```

With AS 3.0, you have to add eventListeners to each of your buttons where each eventListener calls a function, but how can I write it so I don’t have to write a bunch of if statements inside the function the eventListeners are calling in order to test for which button is being clicked? Like so:

```auto

button1_mc.addEventListener(MouseEvent.CLICK, movePlayHead);
button2_mc.addEventListener(MouseEvent.CLICK, movePlayHead);
button3_mc.addEventListener(MouseEvent.CLICK, movePlayHead);

function movePlayHead(event:MouseEvent):void
{
     if(event.target == button1_mc){
          gotoAndStop("label1");
     }
     if(event.target == button2_mc){
          gotoAndStop("label2");
     }
     ETC...
}

```
