[Cocos Creator] How To use cc.Event.EventCustom

[Cocos Creator] How To use cc.Event.EventCustom
0.0 0

#1

Hi all,
I’m a newbie, i have a problem

  • i have a file GamePlay.js:

cc.Class({extends: cc.Component,

 start () {
      this.node.on('custom_event',function(event){
          cc.log('==============this is custom event');
      });
  },

});

and file Hero.js

cc.Class({ extends: cc.Component,

 update: function (dt) {
       var Custom_Event = new cc.Event.EventCustom('custom_event', true);
       this.node.dispatchEvent(Custom_Event);
  }, 

});

but in gameplay.js can’t recieve event,
who can help me, thanks.


#2

You have to listen on the object that emits the event. On GamePlay you do something like

start () {
      this.heroGameObject.node.on('custom_event',function(event){
          cc.log('==============this is custom event');
      });
  },