Event Emit Error

Event Emit Error
0.0 0


Why node.emit in not passing the data info of my event?

onCollisionEnter : function(other){
other.node.emit(“takeDamage”, {amount: 10});

When I receive the evento on the other object the detail paramenter is always undefined.


Do you have a test project to evaluate the issue?


TestProject.zip (220.0 KB)

For sure, here it is.

thank you


The function that will be called when the event triggers only have 1 parameter: event
The data you sent is inside “event.detail”

So your function should be:

teste: function(event){

Check this to get a list of the event properties: http://cocos2d-x.org/docs/api-ref/creator/v1.5/classes/Event.EventCustom.html


Even if I do that the current event.detail return undefined. Have you tried?


I have built a game around custom events.
And I have tried with your project and works great.


What version of Cocos creator are you using?


But it works in all versions.


I’ve updated my versio to 1.7 and it started to work. Apparently it didnt on versio 1.6.2


Just stumbled upon this issue, in v1.6.2 CC reuses event objects, so if you keep the whole event object and access event.detail later it gets messed up by other emitted events. Thus you need to store event.detail immediately in eventListener if you plan to use it later