How to modify by script the string of a richText node?

Hello, my question is concerning scripting in cocos creator.
is it possible to modify by script the string of a richText node and how to do it ?
I have access to my richText node (which alias is “MyText” in the hierarchy) by using this :

var texte = cc.find(“blabla/bla/MyText”, this.node);
and when I use
alert(texte.name);
it gives “MyText”, ok

but I dont know how to change the string content… is there a kind of setString() method ?
also when I want to access to the string property of my node by using
alert(texte.string);
it gives undefined
could you help me please to solve this ?

Hello, try this:

var text = cc.find("blabla/bla/MyText", this.node).getComponent(cc.RichText);
text.string = "sometext";
cc.log(text.string);
1 Like

Ok, I think I begin to understand the logic… Thank you very much for helping.