美文网首页
LayaBox自定义事件

LayaBox自定义事件

作者: 深海不蓝丶 | 来源:发表于2018-11-09 15:59 被阅读0次

EventMgrts.ts文件

import EventDispatcher = laya.events.EventDispatcher;
class EventMgr extends EventDispatcher {
    static eventDispatcher: EventDispatcher = new EventDispatcher();
    static _instance: EventMgr;
    public static getInstance() {
        if (EventMgr._instance == null) {
            EventMgr._instance = new EventMgr();
        }
        return EventMgr._instance;
    }
    constructor() {
        super();
    }
    ///注册事件
    public Emit(InName, agv?: null) {
        //派发事件
        console.log("派发事件",InName);
        EventMgr.eventDispatcher.event(InName, agv);
    }
    //侦听事件
    public AddNotice(InName, caller, listener: Function, arg?: any[]): void {
        console.log("侦听事件",InName);
        EventMgr.eventDispatcher.on(InName, caller, listener, (arg == null) ? null : ([arg]));
    }
}

添加侦听事件

EventMgr.getInstance().AddNotice("test", this, this.onAddNotice);

注册事件

 EventMgr.getInstance().Emit("test");

相关文章

  • LayaBox自定义事件

    EventMgrts.ts文件 添加侦听事件 注册事件

  • LayaBox实现自定义List

      学习LayaBox已经有10多天了,今天在LayaBox官网教程中学习到了如何制作自定义List,结合自己的理...

  • LayaBox自定义组件

    最近在写自己游戏的过程中,自己写了个ScaleButton(点击带缩放的按钮),通过组件名字,通过附加的方式,来实...

  • LayaBox之搭建TS开发环境

    1.下载LayaIDE和TS源码 进入LayaBox官网www.layabox.com,选择LayaAir Eng...

  • 自定义事件js

    title: 自定义事件date: 2017-06-06 15:36:04tags: 自定义事件 js的自定义事件...

  • layabox-url

    https://www.layabox.com/

  • jQuery例子记录(持续更新)

    目录: 1.自定义事件2.操作DOM(与JS原生对比) 1.自定义事件 绑定自定义事件: 事件名称refresh....

  • JavaScript之事件完整篇

    目录html原生事件自定义事件node中的自定义事件前端框架的自定义事件 一、html原生事件 1. 概念 观察者...

  • springboot之事件监听

    springboot事件监听 自定义事件 自定义事件继承至ApplicationEvent,事件类不能注册为spr...

  • this.$emit()

    this.$emit("自定义事件") 通过触发自定义事件,来给触发监听事件

网友评论

      本文标题:LayaBox自定义事件

      本文链接:https://www.haomeiwen.com/subject/fnsoxqtx.html