I just wondering if there a way to optimize the way of changing color of numbers in stock exchange template by using expressions? When I put the +before the number it turns green and if -,it turns red.
1 Answer
This is probably not the shortest way of doing it, but it's quick and easy:
- Make a null layer with a slider
- Make a text layer with green text
- Link the source text in your text layer to the slider in the null layer.
You should see an expression like this:
thisComp.layer("slider null").effect("Slider Control")("Slider")
Now add an expression to the Opacity control in your text layer. This is going to make the Opacity go to 0 if the slider value is below zero, or 100 if it is zero or above:
if(thisComp.layer("slider null").effect("Slider Control")("Slider")>=0) {100} else {0};
Now duplicate the green text layer
Rename it "red text"
Change the text colour to red
Edit the expression on the red text layer's Opacity control to this:
if(thisComp.layer("slider null").effect("Slider Control")("Slider")<0) {100} else {0};
Now the red text layer should only be visible when the slider value is lower than zero.
Screenshot of the whole thing below:
If you want a leading "+" before the positive values, you could also make an "if/else" statement in the green Source text control, so you only see a "+" when the value is above zero - something like this:
if(thisComp.layer("slider null").effect("Slider Control")("Slider")>0) {"+" + thisComp.layer("slider null").effect("Slider Control")("Slider")} else {thisComp.layer("slider null").effect("Slider Control")("Slider")};