ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trigger a animation using a checkbox

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
George Henderson
Trigger a animation using a checkbox
on Jun 18, 2012 at 7:46:52 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: http://www.mediafire.com/?v0s1qn6wzg91yag



Thank you!

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


Return to posts index

Dan Ebberts
Re: Trigger a animation using a checkbox
on Jun 18, 2012 at 8:39:35 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



Return to posts index

George Henderson
Re: Trigger a animation using a checkbox
on Jun 18, 2012 at 9:42:01 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!


Return to posts index



Dan Ebberts
Re: Trigger a animation using a checkbox
on Jun 18, 2012 at 10:10:27 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



Return to posts index

George Henderson
Re: Trigger a animation using a checkbox
on Jun 19, 2012 at 11:21:33 pm

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


Return to posts index

George Henderson
Re: Trigger a animation using a checkbox
on Jun 21, 2012 at 8:09:44 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


Return to posts index



Dan Ebberts
Re: Trigger a animation using a checkbox
on Jun 21, 2012 at 10:43:07 pm

Try replacing this:

if (gotit) time-t else 0;

with this:

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


Dan



Return to posts index

George Henderson
Re: Trigger a animation using a checkbox
on Jun 22, 2012 at 3:45:27 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!


Return to posts index

Sander van Dijk
Re: Trigger a animation using a checkbox
on Jul 11, 2016 at 1:10:43 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


Return to posts index


irma crusat
Re: Trigger a animation using a checkbox
on Nov 1, 2016 at 8:45:47 pm

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


Return to posts index

ido shor
Re: Trigger a animation using a checkbox
on Nov 30, 2016 at 9:32:41 am

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

Keep on your holy work ;)


Return to posts index

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