Musab
March 20, 2019, 3:26pm
#1
properties: {
balloon0btl: {
default: null,
type: cc.RichText
},
balloon1btl: {
default: null,
type: cc.RichText
},
balloon2btl: {
default: null,
type: cc.RichText
},
},
i have this objects in my script they are different richtexts i wanna choose one depending on the paramater of function and change its strings value
here is what i tried and didnt work
var selectb = function (be) {
var n = String("balloon"+be+"btl");
this.n.string = selectedtxt;
};
selectb(cbal);
i know this isnt exactly a problem related to cocos but i hope you guys can help thanks in advance
igomes
March 21, 2019, 9:23am
#2
I would create an array property instead. Since your “be” parameter is the index, this should map pretty easily to the array.
1 Like
Orlan
March 21, 2019, 7:48pm
#4
You should be able to access the property with this[n]
So in your case
this[n].string = selectedtxt;
1 Like
igomes
March 21, 2019, 11:04pm
#5
Sure. I am using Typescript, so you would declare a property member like this:
@property([cc.RichText])
public balloons: cc.RichText[] = [];
And you can access them by using:
const balloon = this.balloons[be]; // in this case, "be" is a number, not a string.
// do whatever you want to the balloon object (which is a cc.RichText).
Musab
March 22, 2019, 1:56am
#6
this is how i do it with js
balloons: [cc.RichText],
system
closed
March 23, 2019, 1:56am
#7
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.