Itemrenderer 调度自定义事件 [英] Itemrenderer Dispatch Custom Event

查看:32
本文介绍了Itemrenderer 调度自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从自定义 ItemRenderer 分派自定义事件

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

这是我的自定义事件

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;
        }
    }
}

itemRenderer 中,我有一个函数可以做到这一点:

In the itemRenderer I have a function that does that:

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

在主应用程序中,我有一个 spark 列表,我尝试向应用程序和列表本身添加一个 EventListener,但它们从未被调用...

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.

在您的自定义事件构造函数中添加 bubbles 参数(默认情况下为 false):

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;
        }

可以在此处找到有关 AS3 中事件冒泡的很好解释:AS3 中的事件冒泡

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

这篇关于Itemrenderer 调度自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆