分以下几种情况:
定义在properties中的属性
类型为cc.Label
cc.Class({
properties: {
myLabel:cc.Label,
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start() { },
onClickBtn:function(){
this.myLabel.string="New字符串";
},
}
类型为cc.Node
cc.Class({
properties: {
myLabel:cc.Node,
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start() { },
onClickBtn:function(){
this.myLabel.getCompenent(cc.Label).string=“New字符串”;
},
}
未在properties中定义属性
cc.Class({
properties: {},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start() { },
onClickBtn:function(){
//myLabel为在场景中添加的位于Canvas下的Label
this.node.getChildByName("myLabel").getComponent(cc.Label).string=“New字符串”;
//下面代码效果相同
//cc.find("Canvas/myLabel").getComponent(cc.Label).string="New字符串";
},
}