AE: Expressions – a light switch

In my scenario I have two different sets of artwork, one for a lit room and one where the light is off.
So two different images for each element in my scene.  I wanted a checkbox expression control to flip between
100% and 0% opacity on all these different layers and control the “light” going on and off.

Connecting the opacity property didn’t cause trouble, I find that the checkbox returns
either “1” or “0” which makes sense.

thisComp.layer("Null 2").effect("Lightswitch")("Checkbox")*100

The “Checkbox” has been renamed “Lightswitch” and is on a .layer in thisComp called “Null 2”



at the end multiplies the 1 from the checkbox to return 100% opacity or 0% depending on
the state of the switch. Here’s the tricky bit, how to get the 0 from the checkbox interpreted
as 100% opacity and the 1 as 0% opacity to apply to the layers for the alternate state.

For this I consulted an Oxford graduate and he solved it thusly:


so in my comp for the alternate state layers the code looks like this:

((thisComp.layer("Null 2").effect("Lightswitch")("Checkbox") -1)*-100);

So there is now a single controller on Null 2 to switch between my day time and night time layers
with a keyframeable checkbox. Magic.

Leave a Reply

Your email address will not be published. Required fields are marked *