Creative Communities of the World Forums

The peer to peer support community for media production professionals.

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 pm

    Hey 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 pm

    Try 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 pm

    Hi 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

    One small issue though: every time I edit the text it gives me this error:

    It disables the expression and when I enable it – everything is fine again. Until I edit again. Any idea on what the issue might be?

    I’m using AE CS6.

  • Dan Ebberts

    September 17, 2016 at 8:24 pm

    This 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

  • Dmitry Yershov

    September 18, 2016 at 5:06 am

    Thank you very much, Dan!

  • Scott Mcgee

    October 4, 2017 at 12:12 pm

    Hey 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 pm

    Funnily 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 pm

    This 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
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy