Checkbox

Moderators: Disciple, zlovatt

Post Reply
dnbstudios
Posts: 2
Joined: April 14th, 2012, 12:41 pm

Hi - thanks in advance for any help. I'm relatively new to expressions. I'm trying to do something that I realize I could easily do using simple keyframes ... but at this point what I'm trying to do is turning into an expressions lesson.

I'm trying to control the opacity of two layers using a null layer with a checkbox expression control. I'd like to turn the layers on and off. That part isn't hard. The problem is that I'm trying to have each layer work in reverse. In other words, while layer one is at 100% opacity, layer two is at 0% opacity. And then they alternate.

This has become silly to me - but it's made me realize just how limited my knowledge of expressions really is. I've been reading Marcus Geduld's expressions book, and I've been to Dan Ebbert's website - but I can't figure this out. I think it's probably very simple.

Any help would be appreciated. Thanks.

++bronson
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You could do something like:

Code: Select all

if (thisComp.layer("Null 1").effect("Checkbox Control")("Checkbox").value) {
	100;
} else {
	0;
}
The if statement tests if something is "true". i.e if (1 == 1) (if 1 is equal to 1), if (1 < 2) (if 1 is less than 2). The checkbox value is already a boolean value (i.e. true or false) so it's perfect for an if statement.

You could swap those values around for the other layer, or use an expression like this to make one layer's opacity the inverse of another:

Code: Select all

100 - thisComp.layer("The Other Layer").transform.opacity;
dnbstudios
Posts: 2
Joined: April 14th, 2012, 12:41 pm

Brilliant! Thank you! That works great and it really helped me understand the problem.

I love discussion boards like this. I really appreciate the help.

++bronson
Post Reply