ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trigger keyframed effect with checkbox controller

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Joe Canter
Trigger keyframed effect with checkbox controller
on Jan 15, 2019 at 9:22:51 pm

So, I have a drop shadow effect that animates in and out and I need it to do that several times in a sequence. The composition has many layers, so I've linked most of the animated elements to a control layer. My goal was to trigger the animation using a control checkbox.

I tried several things that didn't work. Then I found this expression but it only partially works and I can't figure out what's wrong:

p = thisComp.layer("Controls").effect("Top Shadow")("Checkbox");
if (p.value){
gotit = false;
t = time;
while (t >= 0){
if (! p.valueAtTime(t)){
gotit = true;
break;
}
t -= thisComp.frameDuration;
}
if (gotit) time-t else 0;
}else
0


When I turn the checkbox on, the opacity does begin to fade in. However, instead of fading from 0 to 16% over 20 frames, the opacity slowly rises to 100% over the duration of the entire sequence.

Can anyone help me with this?


Return to posts index

Dan Ebberts
Re: Trigger keyframed effect with checkbox controller
on Jan 15, 2019 at 10:39:00 pm

This might get you started. It will trigger the animation wherever there's a keyframe on the checkbox:


p = thisComp.layer("Controls").effect("Top Shadow")("Checkbox");
n = 0;
if (p.numKeys > 0){
n = p.nearestKey(time).index;
if (p.key(n).time > time) n--;
}
n > 0 ? time - p.key(n).time : 0;



Dan



Return to posts index

Joe Canter
Re: Trigger keyframed effect with checkbox controller
on Jan 16, 2019 at 2:38:51 pm

When I apply that expression to the drop shadow effect's opacity, and set a keyframe for the checkbox, it does trigger the opacity to start to fade in, but I have the same problem: instead of fading in from 0% to 100% over 20 frames, it just slowly rises to 100% over the course of about 3,000 frames. What elements of my composition could be interfering with this expression?


Return to posts index


Dan Ebberts
Re: Trigger keyframed effect with checkbox controller
on Jan 16, 2019 at 6:08:40 pm

If your layer already has an opacity animation starting at time 0, change the last line of the expression to this:

t = n > 0 ? time - p.key(n).time : 0;
valueAtTime(t)

If it doesn't, try this:

t = n > 0 ? time - p.key(n).time : 0;
linear(t,0,framesToTime(20),0,100)



Dan



Return to posts index

Joe Canter
Re: Trigger keyframed effect with checkbox controller
on Jan 17, 2019 at 6:40:05 pm

Thanks, Dan! That does cue the keyframe animation when the checkbox is activated.

If I wanted to keyframe the checkbox so that when it's turned off, the keyframes will reverse, is there a simple line of expression to do this? I tried a few variations of examples I found but they seemed to be more complex and either did nothing or just turned the effect off instantly.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]