# Button function with arguments?

**URL:** <https://forum.kirupa.com/t/button-function-with-arguments/278780>\
**Category:** Uncategorized\
**Created:** [January 5, 2009, 7:22pm UTC](https://forum.kirupa.com/t/button-function-with-arguments/278780 "2009-01-05T19:22:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobcooper](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@bobcooper](https://forum.kirupa.com/u/bobcooper)\
**Post date:** [January 5, 2009, 7:22pm UTC](https://forum.kirupa.com/t/button-function-with-arguments/278780/1 "2009-01-05T19:22:47Z")

</div>

Hi there,

I just had a curious thought and wondered if anyone knew if this is possible, if I had three buttons with the following functions:

```auto
first_btn.addEventListener(MouseEvent.MOUSE_UP,firstButton);
function firstButton(event:MouseEvent){
    trace("button 1");
}

second_btn.addEventListener(MouseEvent.MOUSE_UP,secondButton);
function secondButton(event:MouseEvent){
    trace("button 2");
}
 
 third_btn.addEventListener(MouseEvent.MOUSE_UP,thirdButton);
 function thirdButton(event:MouseEvent){
    trace("button 3");
 }

```

Now this feels like a lot of repetitive functions so I was wondering if there was a way to add arguments to button functions e.g. something like this:

```auto
first_btn.addEventListener(MouseEvent.MOUSE_UP,buttonPressed(1));
second_btn.addEventListener(MouseEvent.MOUSE_UP,buttonPressed(2));
third_btn.addEventListener(MouseEvent.MOUSE_UP,buttonPressed(3));

  function buttonPressed(event:MouseEvent, buttonNumber){
     trace("button " + buttonNumber);
  }

```

Any ideas how to go about doing this?

Cheers

Bob
