Sender custom event

I am trying to send 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 itemRenderer , I have a function that does this:

  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 to both the application and the list itself, but they are never 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 was sent correctly ... I cannot intercept it.

+4
source share
1 answer

It looks like your event is not bubbling.

Add the bubbles argument (which is false by default) to your custom event constructor:

 public function CopyProductEvent(type:String, picked:Product, bubbles:Boolean = true) { super(type,bubbles); this.picked = picked; } 

A good explanation of the AS3 event popup can be found here: Bubbling Event in AS3

+9
source

Source: https://habr.com/ru/post/1396601/


All Articles