问题描述
我想从定义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));
}
和在主应用程序我有一个火花列表,然后我尝试添加一个事件监听两个应用程序和列表本身,但他们从来没有被称为...
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;
}
在事件冒泡在AS3一个很好的解释可以在这里找到:事件冒泡在AS3
A nice explanation on Event bubbling in AS3 can be found here:Event Bubbling in AS3
这篇关于itemRenderer的调度自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!