title: adding a custom event listener in as3
body: <p>I've done a lot of reading through forum posts and tutorials, but I still can't wrap my brain round events and event listeners. I have a pretty simple example, but I can't get it to work.</p>
  
  <p>I have an arrayCollection of custom objects in a repeater, when one of those objects is clicked, I want a different componenet to display data associated with that object.</p>
  
  <p>Here's what I have, but the listener never responds (the dispatcher seems to be working though, because the new event is created and I can see the trace with the proper output.) I suspect it is because when I call addEvent Listener, I am doing so on the wrong object. My understanding is that the object that will display the object data is the object that should have the event listener, and listen for all events of this nature, but maybe I misunderstood.</p>
  
  <p>My custom event:</p>
  
  <pre><code>public class SelectObjectEvent extends Event
      {
          public function SelectObjectEvent(customEventString:String, myObject:customObject)
          {
                super(customEventString, true, false);
                trace(customEventString+" "+myObject);
          }
      }
  }
  </code></pre>
  
  <p>My custom object has the following function which is called on click:</p>
  
  <pre><code>public function selectObject(myObject:customObject):void
          {
              dispatchEvent(new SelectObjectEvent("OBJECT_SELECTED", customObject));              
          }
  </code></pre>
  
  <p>And the component I want to display the selected object has the following constructor:</p>
  
  <pre><code>public function SelectedObjectDisplayClass()
          {
              addEventListener("OBJECT_SELECTED", this.showObject)
          }
  
          public function showObject(event:Event):void
              {  
              trace("Show object: "+event); 
          } 
  </code></pre>