FORUMS: list search recent posts

Change the color of a specific word in a sentence with expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Liam Campbell
Change the color of a specific word in a sentence with expression
on Dec 6, 2016 at 3:46:19 pm

I'm trying to change the color of specific words that are part of a larger sentence. Is there a way to "access" a string of letters in the source text to change the color of just that word?


Return to posts index

Dan Ebberts
Re: Change the color of a specific word in a sentence with expression
on Dec 6, 2016 at 5:49:59 pm

This is a simplistic example that might get you started. Add a Fill Animator to your text layer, then add an Expression Selector, then add this expression to the Expression Selector's Amount property:

targetWord = "test";
txt = text.sourceText;
idx = txt.indexOf(targetWord);
if (idx > -1){
if (textIndex > idx && textIndex <= (idx + targetWord.length)){
100
}else{
0
}
}else
0

If your text has the word "test" in it, it should be red. This has a lot of limitations though. Only the first occurrence of the word will be colored. It won't work right if your text is multi-line. It doesn't account for capitalization (e.g., it won't match "Test").

You could certainly come up with a more robust solution, depending on your requirements.

Dan



Return to posts index

Liam Campbell
Re: Change the color of a specific word in a sentence with expression
on Dec 6, 2016 at 7:01:25 pm

Thank you for answering, could you document what some of the lines are doing for me just to help me understand a little bit more what's going on?

Thanks


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]