1 Reply Latest reply on Feb 15, 2012 9:29 AM by Claudiu Ursica

    Itemrenderer Dispatch Custom Event

    Z4g0s Level 1

      I'm trying to dispatch a custom event from a custom ItemRenderer

      This is my custom event

       

       

      package events
      {
          import customClass.Product;
      
      
          import flash.events.Event;
      
      
          public class CopyProductEvent extends Event
          {
              public static const COPY_PRODUCT:String = "COPY_PRODUCT";
              public var picked:Prodotti;
      
      
              public function CopyProductEvent(type:String, picked:Product)
              {
                  super(type);
                  this.picked = picked;
              }
          }
      }
      
      

       

      In the itemRenderer I have a function that does that:

       

       

      private function sendEvent(o:Product):void
              {
                  dispatchEvent(new CopyProductEvent(CopyProductEvent.COPY_PRODUCT,o));
              }
      
      


      And in the main application I have a spark List and I tried to add an EventListener both to the application and the list itself, but they never be called...

       

       

      this.addEventListener(CopyProductEvent.COPY_PRODUCT,
              function(e:Product):void{
                  ...
          });
      
      
          list.addEventListener(CopyProductEvent.COPY_PRODUCT,
              function(e:Product):void{
                  ...
          });
      
      

       

      Why?!? Where am I doing wrong?

      The event from the function is dispatched correctly... I can't intercept it..

      I also tried to extend the spark List w/o luck

       


      package components
      {
           import spark.components.List;
      
      
           [Event(name="COPY_PRODUCT", type="events.CopyProductEvent")]
      
      
           public class ListProduct extends spark.components.List
           {
               public function ListProduct()
               {
                     super();
               }
           }
      }
      
      

        • 1. Re: Itemrenderer Dispatch Custom Event
          Claudiu Ursica Level 4

          Override clone() method inside event to make sure you take into account the bubbling property, and then inside renderer dispatch the event with bubbling property set to true.

          Alternatively you can dispatch on the list e.g :

           

          owner.dispatchEvent(newCopyProductEvent(CopyProductEvent.COPY_PRODUCT,o));

           

          If you choose to do the latter make sure you don;t get into an infinite loop inside list if you decide to redispatch from there,

           

          C