Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger a animation using a checkbox

  • Trigger a animation using a checkbox

    Posted by George Henderson on June 18, 2012 at 7:46 pm

    Hello everyone,
    I’m trying to trigger a animation using a on/off switch.
    The animation is a ball scaling up and down in 50 frames. (0 = 100% – 25 = 308% – 50 = 100%)
    The ball animation is nested and I would like to trigger the animation from the main comp.
    The on/off switch (null) is inside of the main comp and the value changes based on keyframes.

    My approach to this was to enable ‘time remmaping’ for the ball comp inside of the main root. Then i pick-whipped to the on/off checkbox.

    Now I’m not sure how to tell after effects to play the ball animation from frame 0 to 50 (doesn’t have to play all 50 frames) whenever the checkbox is ticked.

    I have uploaded a simplified version of the Ball project for you to work with. Any help would be greatly appreciated.

    Project file: https://www.mediafire.com/?v0s1qn6wzg91yag

    Thank you!

    b = thisComp.layer("On/Off Switch").effect("Checkbox Control")("Checkbox");

    Dan Ebberts
    replied 7 years, 9 months ago
    6 Members · 12 Replies
  • 12 Replies
  • Dan Ebberts

    June 18, 2012 at 8:39 pm

    Try this:


    n = 0;
    p = thisComp.layer("On/Off Switch").effect("Checkbox Control")("Checkbox");
    if (p.numKeys > 0){
    n = p.nearestKey(time).index;
    if (p.key(n).time > time) n--;
    }
    if (n > 0 && p.key(n).value)
    time - p.key(n).time
    else
    0

    Dan

  • George Henderson

    June 18, 2012 at 9:42 pm

    That totally did the trick.
    Now would it be possible to get the same result using a wiggle instead of keyframing the Ball comp?

    By that I mean having ‘wiggle(.5,5)’ on the On/Off checkbox.

    Thanks!

  • Dan Ebberts

    June 18, 2012 at 10:10 pm

    I haven’t tried this, but it will probably look like this:


    p = thisComp.layer("On/Off Switch").effect("Checkbox Control")("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

    Dan

  • George Henderson

    June 19, 2012 at 11:21 pm

    I just want to confirm that both methods worked.
    A million thanks Mr. Ebberts 🙂

  • George Henderson

    June 21, 2012 at 8:09 pm

    Hello,
    As far as I can tell ‘thisComp.frameDuration’ tells it to play the animation from frame 0 all the way to the end.
    Is it possible to hold the animation at a certain frame?
    Say if the animation is 50 frames, can it play 0 to 42 and hold on frame 42?

    I could just cut down the animation to 42 frames, but once the checkbox is set to ‘off’ it’ll reset back to 0 on time remap.

    I would like to hold frame 42 while the checkbox is off.

    Thanks!

    p = thisComp.layer("On/Off Switch").effect("Checkbox Control")("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

  • Dan Ebberts

    June 21, 2012 at 10:43 pm

    Try replacing this:

    if (gotit) time-t else 0;

    with this:

    if (gotit) Math.min(time-t,framesToTime(42)) else 0;

    Dan

  • George Henderson

    June 22, 2012 at 3:45 pm

    It does hold on the 42nd frame of the animation, but once the checkbox is disabled, it resets back to the first frame.

    *I updated the project file with the latest code.

    4326_checkboxv2.aep.zip

    Thanks!

  • Sander Van dijk

    July 11, 2016 at 1:10 am

    hallo,

    Any idea how to make this animate from frame 42 to 0 again once the trigger is switched off again?

    Thanks!

    p = thisComp.layer("On/Off Switch").effect("Checkbox Control")("Checkbox");
    if (p.value){
    gotit = false;
    t = time;
    while (t >= 0){
    if (! p.valueAtTime(t)){
    gotit = true;
    break;
    }
    t -= thisComp.frameDuration;
    }
    if (gotit) Math.min(time-t,framesToTime(42)) else 0;
    }else
    0

  • Irma Crusat

    November 1, 2016 at 8:45 pm

    did you ever find a solution? i am stuck with the same problem. 4 years later 🙂

  • Ido Shor

    November 30, 2016 at 9:32 am

    Just wanted to say, this is a G-R-E-A-T expression Dan.

    Keep on your holy work 😉

Page 1 of 2

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