LayaAir入门之EventDispatcher类

EventDispatcher类,继承自Object类,是可调度事件的所有类的基类。

常见的例如作为基础节点的Node类也是继承此类。

只要继承了此类,就可以作为一个事件发送者,发送事件给它的监听者。


主要方法:


// 是否有指定类型的监听者

hasListener(type: string): boolean;


// 派发事件

event(type: string, data?: any): boolean;


// 监听事件

on(type: string, caller: any, listener: Function, args?: Array<any>): EventDispatcher;


// 监听一次事件

once(type: string, caller: any, listener: Function, args?: Array<any>): EventDispatcher;


// 移除监听

off(type: string, caller: any, listener: Function, onceOnly?: boolean): EventDispatcher;

// 如果onceOnly为 true ,则只移除通过 once 方法添加的侦听器


// 移除所有指定类型的监听

offAll(type?: string): EventDispatcher;

// 如如果type为 null,则移除本对象所有类型的侦听器


// 判断事件类型是否是鼠标事件

isMouseEvent(type: string): boolean;


猜你喜欢

转载自blog.51cto.com/ymdzz/2110935
今日推荐