Checkbox Fade

A Checkbox Control shows or hides a layer — with a smooth timed fade instead of a hard cut when keyframed.

Expression Code
// Checkbox Fade
// Apply to Opacity
// Add a Checkbox Control named "Show"
fadeDur = 0.5; // Fade length in seconds
chk = effect("Show")("Checkbox");
out = chk.value * 100;
if (chk.numKeys > 0) {
n = chk.nearestKey(time).index;
if (chk.key(n).time > time) n = n - 1;
if (n < 1) {
// Before the first key, AE holds that key's value
out = chk.key(1).value * 100;
} else {
// Walk the keys so an interrupted fade stays continuous:
// each fade starts from wherever the previous fade actually reached.
cur = chk.key(1).value * 100;
for (i = 1; i <= n; i++) {
target = chk.key(i).value * 100;
if (i < n) {
tEval = chk.key(i + 1).time;
} else {
tEval = time;
}
cur = linear(tEval - chk.key(i).time, 0, fadeDur, cur, target);
}
out = cur;
}
}
out;
Add Effect > Expression Controls > Checkbox Control, rename it to "Show", and apply the expression to Opacity. An unkeyframed checkbox switches the layer instantly — the right behaviour for a static template toggle. Keyframe the checkbox and every toggle after the first becomes a timed fade starting at its keyframe; the first keyframe just establishes the starting state, so no phantom fade happens there.
Back to React & Effect