Event Emit Error


#1

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.


#2

Do you have a test project to evaluate the issue?


#3

TestProject.zip (220.0 KB)

For sure, here it is.

thank you


#4

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){
    console.log(event.detail);
}

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


#5

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


#6

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


#7

What version of Cocos creator are you using?


#8

1.5.2.
But it works in all versions.


#9

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


#10

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