如题,我使用了cocos creator预制的botton按钮,他下面有一个Label子类,我的需求是:点击该按钮时按钮的文字会进行变化,但是不知道该语法要怎么写,还望各位帮忙。

其中在调用btn:function()的时候,第一个
this.label.string = this.data;
是改变其他地方的一个label文字,可以实现,第二个 this.node.getChildByName(‘Label’).string = this.name1 ;
就不行了
但是如果改变字体颜色,使用
this.node.getChildByName(‘Label’).color = xxxx;
的话也可以成功,请教一下这后面应该是 .什么语法才能实现我的需求?
getChildByName
通过名称获取节点的子节点。
返回 Node
Node != Label
https://docs.cocos.com/creator/api/zh/classes/Node.html#getchildbyname
应该使用这个:
getComponent
获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
传入参数也可以是脚本的名称。
meta description
返回 Component
this.node.getChildByName(‘label’).getComponent(cc.Label).string = this.name1;
2赞
解决了,谢谢!

