3 Replies Latest reply on Sep 1, 2009 8:54 PM by babo_ya

    Add listener to custom component?

    alejandrorrr Level 1

      Hello Everyone!

       

      First of im starting to learn abount events, so go easy on me.

       

      I have custom component based on Vbox called "MsgRenderer" which throws an custom event, which i call from MXML like this:

       

      <mx:List id="msgList" dataProvider="{ac}" >

      <mx:itemRenderer>
           <mx:Component>
               <ns1:MsgRenderer>
               </ns1:MsgRenderer>
           </mx:Component>
      </mx:itemRenderer>  

      </mx:List> 

       

      How do i attach a listener to MsgRenderer? if i try adding an "id" attribute i get:

       

      Id attribute is not allowed on root tag of component

       

       

      Any ideas or tips are welcome!!

       

      Thanks

        • 1. Re: Add listener to custom component?
          babo_ya Level 3

          Not sure why, somehow this doesn't look right.

          I could be wrong but, not sure how to add an event listener to a custom renderer..

          Most of time I add an event listener to the data object (in your case "ac" arraycollection)

           

          for example,

           

          let's say that the first item on your ac arraycollection is an EmployeeVO object ... then make sure this VO extends from EventDispatcher..

           

          firstVO.addEventListener("YOurEventType", handler);

           

          hope this helps,

           

          BaBo,

          1 person found this helpful
          • 2. Re: Add listener to custom component?
            alejandrorrr Level 1

            Babo,

             

                  Thanks for taking the time to answer. Actually you are sort of right. At the end i found out that i should attach the listener to the List (MsgList in my case) and not the itemrenderer itself. turns out that at the end what i have is a problem (which im trying to work out) with my Custom Event which is not bubbling (it is inside a component inside my itemRenderer).

             

            Thanks a lot for answering though, i appreaciate your effort!

             

             

            Alex

            • 3. Re: Add listener to custom component?
              babo_ya Level 3

              YOu probably know this already but, in your custom event .. you can..

               

              super(type, bubble); ..   i think

               

              hope this helps,

               

              BaBo,