Activity › Forums › Adobe After Effects Expressions › Is it possible to partially change color of text with Expressions
-
Is it possible to partially change color of text with Expressions
Posted by Dmitry Yershov on September 17, 2016 at 12:47 pmHey everyone,
I’m trying to do a Twitter template and I want the user to be able to change colors of text and links separately with expressions. Is it possible to get regular text be Color 1 and words starting with # or @ – Color 2?
Thanks!
Scott Mcgee replied 8 years, 8 months ago 3 Members · 8 Replies -
8 Replies
-
Dan Ebberts
September 17, 2016 at 3:55 pmTry this:
1) add a Fill Color animator for Color 2
2) add an Expression Selector
3) replace the expression for the Expression Selector’s Amount property with this:
myChar = "";
for (i = textIndex; i > 0; i--){
c = text.sourceText[i-1];
if (c == " ") break;
myChar = c;
}
if (myChar == "@" || myChar == "#") 100 else 0
Dan
-
Dmitry Yershov
September 17, 2016 at 4:34 pmHi Dan,
You are a GOD. Thank you so much, that worked really nicely, just what I needed.
-
Dmitry Yershov
September 17, 2016 at 6:35 pm -
Dan Ebberts
September 17, 2016 at 8:24 pmThis should take care of it:
try{
myChar = "";
for (i = textIndex; i > 0; i--){
c = text.sourceText[i-1];
if (c == " ") break;
myChar = c;
}
if (myChar == "@" || myChar == "#") 100 else 0
}catch(e){
value
}
Dan
-
Scott Mcgee
October 4, 2017 at 12:12 pmHey Guys,
This is a brill expression, but for some unknown reason it doesn’t like paragraphing…Is there a little bit more that can be added to the expression to take into account for this?
I’m taking a stab in the dark that it’s because of this if (c == ” “) break; is just looking at each work in a row, but as soon as I paragraph, if it’s the first word, it doesn’t work, but if you hit space, the word color fills but not the @ or #.
Other than that I’m clueless.
-
Scott Mcgee
October 4, 2017 at 12:21 pmFunnily enough though, if I treat is as a textbox, when it wraps the text…It’s not affected that way.
-
Scott Mcgee
October 4, 2017 at 1:24 pmThis works, but if you hit return on the very first character, or if you delete the space that at the end of the line, it shifts the colour forward one otherwise it works…Yay
try{
myChar = “”;
for (i = textIndex; i > 0; i–){
thisText = text.sourceText.replace(/\r?\n|\r/g, ‘ ‘).replace(/\s{2,}/g, ‘ ‘);
c = thisText[i-1];
if (c == ” “) break;
myChar = c;
}
if (myChar == “@” || myChar == “#”) 100 else 0
}catch(e){
value
}
Reply to this Discussion! Login or Sign Up
