新手求助:emit传送时无法获取到event.detail这个数据,显示undefined,求大神解答

cc.Class({
    extends: cc.Component,

    properties: {
        fore:{//每个人都监听来自前一个人的消息
            default:null,
            type: cc.Node,
        },
    },

    // use this for initialization
    onLoad: function () {
        if(this.fore)//如果有前一个人
        this.fore.on('hello',this.doAction,this);//我们就监听来自前一个人的消息 
        this.node.on('mouseup',function(){        //如果我们被点击
            this.node.emit('hello',this.node.name);//就向身后一个人发消息,消息为自己的名字
            this.node.getChildByName('msg').getComponent(cc.Label).string = 'hello!~~';//和身后的伙伴们打声招呼吧~
        },this);
    },
    
    doAction:function(event){   //收到消息了哦
        let action1 = cc.scaleTo(0.1,-1,0).easing(cc.easeBackOut());
        let action2 = cc.rotateBy(0.1,360).easing(cc.easeBackOut());
        let action12 = cc.spawn(action1,action2);                   //一起摇摆~
        
        let callNext = cc.callFunc(this.callNext,this,event);       //向身后一个人继续发消息哦
        
        let action3 = cc.scaleTo(0.1,1,1).easing(cc.easeBackOut());
        let action4 = cc.rotateBy(0.1,-360).easing(cc.easeBackOut());
        let action34 = cc.spawn(action3,action4);                   //一起摇摆~
        
        this.node.runAction(cc.sequence(action12,callNext,action34));
    },
    
    callNext:function(myCaller,event){
        this.node.emit('hello',event.detail);//我们要保持消息的一致 一开始的名字被存在event.detail中了
        this.node.getChildByName('msg').getComponent(cc.Label).string = 'hello! '+ event.detail; //和一开始的伙伴打声招呼吧~
    }

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});

http://www.cocoachina.com/bbs/read.php?tid-462623.html 以上为教程司令部中的源代码,自己运行后发现了这个问题。
运行结果如图:


请教前辈们,这是怎么回事?源码并未改动过,运行无问题,除了这个event.detail中获取不到数据,其他都OK。在线等,谢谢
PS:正确的显示方式如图:
下过断点,传送的时候,this.node.name有值,如"A"这样的值。所以不知道为什么没有进入到event.detail里面。

event 对象不可以跨帧使用,需要跨帧使用请自己保存里面所需要的属性。

我是新手不是很明白,麻烦大神可以详细说下么?

cc.callFunc(this.callNext,this,event); 改成 cc.callFunc(this.callNext,this,event.detail);

把这句话改一下:
let nodeName = event.detail;
let callNext = cc.callFunc(this.callNext,this,nodeName);

这里改成
callNext:function(myCaller,nodeName){
this.node.emit(‘hello’,nodeName);

1赞

先谢谢大神们,下班回家了,明天试验下你们说的方法啊

谢谢,保存成nodeName再emit果然可以了