Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger keyframed effect with checkbox controller

  • Trigger keyframed effect with checkbox controller

    Posted by Mooshoo Fasa on January 15, 2019 at 9:22 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?

    Mooshoo Fasa replied 7 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    January 15, 2019 at 10:39 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

  • Mooshoo Fasa

    January 16, 2019 at 2:38 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?

  • Dan Ebberts

    January 16, 2019 at 6:08 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

  • Mooshoo Fasa

    January 17, 2019 at 6:40 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.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy