ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

"nearestKey" statement to look only for the previous keyframe

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Leo Mazzei
"nearestKey" statement to look only for the previous keyframe
on Feb 21, 2019 at 4:42:41 pm

Hi, I'm trying to make a layer set it's scale to 30% whenever my current keyframe index is an even number and back to 100% when the keyframe is an odd number.
The problem is the nearestKey statement looks for the next or previous nearest key and I can't figure out how to make the expression look only backwards. Any leads?

Thanks!

s = transform.scale
key = s.nearestKey(time).index

if (key%2 == 0){
[30,30];
}else{
[100,100];
}


Return to posts index

Dan Ebberts
Re: "nearestKey" statement to look only for the previous keyframe
on Feb 21, 2019 at 5:19:44 pm

Try it like this:


s = transform.scale;
key = s.nearestKey(time).index;
if (time < s.key(key).time) key--;
if (key > 0){
if (key%2 == 0){
[30,30];
}else{
[100,100];
}
}else
value



Dan



Return to posts index

Leo Mazzei
Re: "nearestKey" statement to look only for the previous keyframe
on Mar 11, 2019 at 12:29:00 am

Thank you, Dan! You are incredible 😃

Best, L


Return to posts index

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