Itemrenderer 调度自定义事件

发布于 2025-01-05 07:34:18 字数 1129 浏览 5 评论 0原文

我正在尝试从自定义 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 中我有一个函数可以做到这一点:

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

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

    this.addEventListener(CopyProductEvent.COPY_PRODUCT,
        function(e:Product):void{
            ...
    });

    list.addEventListener(CopyProductEvent.COPY_PRODUCT,
        function(e:Product):void{
            ...
    });

为什么?!?我哪里做错了?

函数中的事件已正确分派...我无法拦截它..

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一张白纸 2025-01-12 07:34:18

听起来您的活动没有冒泡。

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文