Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Itemrenderer Dispatch Custom Event

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..

like image 970
Marcx Avatar asked Jan 18 '23 11:01

Marcx


1 Answers

Sounds like your event isn't bubbling.

Add the bubbles argument (which by default, is false) in your Custom event constructor:

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

A nice explanation on Event bubbling in AS3 can be found here: Event Bubbling in AS3

like image 107
James Avatar answered Jan 28 '23 14:01

James