How to implement EventCustom
in CC 3.0?
Looks like the class is no longer available in this version. Should I use Event
instead?
And how to pass setUserData
like in 2.x.x versions?
You don’t need to do it anymore, you can add arguments when emit any event. The old EventCustom create lots of garbage and not easy to use.
https://docs.cocos.com/creator/3.0/manual/en/engine/event/event-emit.html#event-dispatching
I saw this documentation but now I am confused with your answer here. The documentation stated that their is:
this.node.dispatchEvent( new Event.EventCustom('foobar', true) );
this.node.on('foobar', (event: EventCustom) => {
event.propagationStopped = true;
});
As you said, EventCustom is not needed any more.
So I need to use xx.emit
instead?
Oh, it’s two different things, and the documentation need to be updated.
-
emit
is for simple event emission -
dispatchEvent
is for dispatch in a capture/bubble process
Currently in v3, we only support dispatchEvent for touch and mouse events. Normally, emit is enough for all cases. If you need to dispatch to parents node of the target node, you should extend the Event class for your own designed behavior.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.