-
Automatically assign fill color to text characters
Hi!
I’m struggling with an expression problem. I’m trying to simulate color coding of text like a password generator does (see attachment). I’ve tried to add expressions to text animators with code like this on the fill property of the animator (I’m not a coder, so blame AI if this is the issue 😊)// Define colors
letterColor = [1,0,0,1]; // Red
numberColor = [0,1,0,1]; // Green
symbolColor = [0,0,1,1]; // Blue
txt = text.sourceText.toString();
c = (textIndex > 0 && textIndex <= txt.length) ? txt.charAt(textIndex-1) : “”;
if (c.match(/[A-Za-z]/)) {
letterColor;
} else if (c.match(/[0-9]/)) {
numberColor;
} else {
symbolColor;
}
I keep getting a “Reference Error: texIndex is not defined”
I’ve also tried to apply an expression to the source text property with a style.setFill() with even less luck.
Any suggestion to getting this to work? Any help would be appreciated!