سؤال

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

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top