0 Replies Latest reply on Apr 30, 2010 11:19 AM by K-kOo

    Dispatching an event from an itemRenderer

    K-kOo

      Hello everybody,

       

      I can't find what is the best way to do that with spark.

      I have a SkinnableComponent that implements IDataRenderer (it owns a button called "addBtn"). I am using it as the itemRenderer of a dataGroup. The skin is a copy of ComboBox skin.

       

      My custom combobox component class (which is using the copied combobox skin) is doing so:

       

      override protected function partAdded(partName:String, instance:Object):void
      {
           super.partAdded(partName, instance);
           
           if (instance == dataGroup)
           {
                dataGroup.addEventListener("addItem", dispatchAddItemEvent);
           }
      }
      
      override protected function partRemoved(partName:String, instance:Object):void
      {
           super.partRemoved(partName, instance);
           
           if (instance == dataGroup)
           {
                dataGroup.removeEventListener("addItem", dispatchAddItemEvent);
                trace("removing 'addItem' listener on", dataGroup);
           }
      }
      
      public function dispatchAddItemEvent(e:DynamicEvent):void
      {
           trace("Gotcha!")
      }
      
       
      

       

      And my ItemRenderer component class has this:

       

      override protected function partAdded(partName:String, instance:Object):void
      {
           super.partAdded(partName, instance);
           
           if (instance == addBtn)
           {
                addBtn.addEventListener(MouseEvent.MOUSE_DOWN, dispatchAddItemEvent);
           };
      }
      
      private function dispatchAddItemEvent(e:MouseEvent):void
      {
           e.stopImmediatePropagation();
      
           var evt:Event = new Event("addItem", false, false);
           dispatchEvent(evt);
      }
      

       

      Result is, i never see "Gotcha!" in the console . And yet i know for sure that my IRs' parent is the same dataGroup from upthere. So i dont really understand what's happening here.

       

      Now i know that if i do new Event("addItem", true, true) it would work, but i dont like bubbling . Do i HAVE to ???

       

      Cheers !