监听事件可以跨文件吗

我在文件a.ts里监听了
this.node.on(“HuntFish”,this.HuntFish,this);

private HuntFish(msg)
{
    console.log("=================================================" + msg);
}

然后在b.ts用下面2个触发方式都没方法触发,是为什么呢

this.node.emit(‘HuntFish’, ‘Hello, this is Cocos Creator’);
this.node.dispatchEvent(new cc.Event.EventCustom(“HuntFish”,true));

这是冒泡事件 全局监听cc.systemEvent.on(string, callback,target) 发射事件 cc.systemEvent.dispatchEvent(new cc.Event.EventCustom(string, false));

1赞

两个文件this.node指向不同,你应该建一个全局的变量监听

谢谢各位大佬哈