# A Listener to many buttons

**URL:** <https://forum.kirupa.com/t/a-listener-to-many-buttons/186586>\
**Category:** flash\
**Created:** [April 22, 2006, 4:26pm UTC](https://forum.kirupa.com/t/a-listener-to-many-buttons/186586 "2006-04-22T16:26:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayman](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Ayman](https://forum.kirupa.com/u/Ayman)\
**Post date:** [April 22, 2006, 4:26pm UTC](https://forum.kirupa.com/t/a-listener-to-many-buttons/186586/1 "2006-04-22T16:26:57Z")

</div>

Hi Guys,

Just a quick logical question.

I have a listener object, and I have around 4 buttons on the stage. I add this same listener object to each of the 4 buttons.

Now when I get an onRelease event, how do I know which button it came from?

Thanks!

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 22, 2006, 8:02pm UTC](https://forum.kirupa.com/t/a-listener-to-many-buttons/186586/2 "2006-04-22T20:02:53Z")

</div>

If you mean Button components, then use the event object passed to the function:

```auto
b0.addEventListener("click", this);
b1.addEventListener("click", this);
b2.addEventListener("click", this);
b3.addEventListener("click", this);
this.click = function(evtObj:Object):Void {
 trace(evtObj.target);
};

```

:disco:

---

<div class="post-metadata">

**Author:** ![Ayman](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Ayman](https://forum.kirupa.com/u/Ayman)\
**Post date:** [April 24, 2006, 1:26am UTC](https://forum.kirupa.com/t/a-listener-to-many-buttons/186586/3 "2006-04-24T01:26:21Z")

</div>

> [@TheCanadian](#):
>
> If you mean Button components, then use the event object passed to the function:
> 
> ActionScript Code:  
> [FONT=Courier New][LEFT]b0.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“click”[/COLOR], [COLOR=#0000ff]this[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
> \<p\>b1.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“click”[/COLOR], [COLOR=#0000ff]this[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
> \<p\>b2.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“click”[/COLOR], [COLOR=#0000ff]this[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
> \<p\>b3.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“click”[/COLOR], [COLOR=#0000ff]this[/COLOR][COLOR=#000000])[/COLOR];\</p\>  
> \<p\>this.[COLOR=#000080]click[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]\</p\>  
> \<p\> [COLOR=#0000ff]trace[/COLOR]COLOR=#000000[/COLOR];\</p\>  
> \<p\>[COLOR=#000000]}[/COLOR];  
> [/LEFT]  
> [/FONT]
> 
> :disco:

wow , thanks !!

If I use a button symbol, I can’t do this , right? It must be a button component?

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 24, 2006, 2:16am UTC](https://forum.kirupa.com/t/a-listener-to-many-buttons/186586/4 "2006-04-24T02:16:53Z")

</div>

By default you can’t but if you wanted to you could rig something up - although it really isn’t necessary :beam:
