标签归档:dispatchEvent

dispatchEvent

有时,有些模块化的东西,要发送事件,如果当然没人侦听它,它却去发送事件不是有点浪费。
有个折中的办法,感谢 tttt 提醒用 willTrigger,willTrigger才能检测事件流里是否有注册相应事件。

注意:不要乱用,因为当事件流的层次多时,willTrigger消耗的时间是dispatchEvent的一多半!

override public function dispatchEvent(event:Event):void
{
    if (willTrigger(event.type))
    {
        super.dispatchEvent(event);
    }
}