# Component Listeners

**URL:** <https://forum.kirupa.com/t/component-listeners/58683>\
**Category:** flash\
**Created:** [July 24, 2004, 11:27pm UTC](https://forum.kirupa.com/t/component-listeners/58683 "2004-07-24T23:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tranism](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tranism/32/269_2.png) [@tranism](https://forum.kirupa.com/u/tranism)\
**Post date:** [July 24, 2004, 11:27pm UTC](https://forum.kirupa.com/t/component-listeners/58683/1 "2004-07-24T23:27:35Z")

</div>

I have two components in my movie, I’m not sure how to write out the code for the listeners. Is it possible to write one listener that listens for changes in both components or do I have to write a separate listener for each? How would this look like written out?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 25, 2004, 7:36am UTC](https://forum.kirupa.com/t/component-listeners/58683/2 "2004-07-25T07:36:12Z")

</div>

You can write one listener for both components. Example:

```auto

listen = new Object(); //create the listener
listen.change = function(evt) { //evt is the object holding a reference to the object calling the event
    if(evt.target == component1) { //evt.target is a reference to the object calling the change function
         //do actions for component1
    } else if(evt.target == component2) {
        //do actions for component2
    }
}
component1.addEventListener("change", listen);
component2.addEventListener("change", listen);

```

Hope this helps :cap:
