Skip to main content
vasulden
Participating Frequently
June 28, 2022
Answered

Need Help with expression. Play auto fade in/out using 'Slider'

  • June 28, 2022
  • 3 replies
  • 690 views

Hey guys, does anyone know how to apply this sort of expression to the opacity parameter, to play auto fade every time when 'Slider' has a keyframe?

This topic has been closed for replies.
Correct answer Dan Ebberts

Not sure exactly what you're doing, but I think you need to find the nearest keyframe to the current time, with something like this:

fDur=0.5; //fade time
p = essentialProperty("Rows");
if (p.numKeys > 0){
  n = p.nearestKey(time).index;
  t = p.key(n).time;
  if (time < t){
    linear(time, t-fDur, t,100, 0);
  }else{
    linear(time, t, t+fDur, 0, 100);
  }
}else
  value

3 replies

Mylenium
Legend
June 28, 2022

Not sure what you need to know. The loop in the example I linked gives you a trigger point from which you can calculate the fades easily just liek the falloff in the audio. in fact this likely could be simplified to using simple subtraction/ addition of the time-spans. Something simple could look like this:

 

fDur=0.5; //fade time

fKeys=thisLayer.transform.opacity.numKeys;

 

if(fKeys != 0){

for (i=1, i < fKeys, i++){

mTime=key(i).time;

mFade=linear(time,mTime,mTime+fDur,100,0);

}}

else{value}

 

Just an example and not tested, but you should get the idea. You likely will need to work in the nearestKey() check from this example as well:

 

http://www.motionscript.com/articles/bounce-and-overshoot.html

 

Mylenium

vasulden
vasuldenAuthor
Participating Frequently
June 28, 2022

thank you so much! 

it seems as it is and I made some customisation and it works nice but only for the second frame, unfortunately. 

here is what I have and 'i' is like a switcher for a specific key frame. when I change it into 'i=2' it started to work with the next key though. Maybe you have an idea of how to make the same result but for every next key by any chance?

 

fDur=0.5; //fade time
fKeys=essentialProperty("Rows").numKeys;
 
if(fKeys != 0) {(i=1, i < fKeys, i++)
	{
	mTime=essentialProperty("Rows").key(i).time;

	Math.max(linear(time,mTime-fDur,mTime,100,0), linear(time,mTime,mTime+fDur,0,100))
	}
}
else{value}

 

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
June 28, 2022

Not sure exactly what you're doing, but I think you need to find the nearest keyframe to the current time, with something like this:

fDur=0.5; //fade time
p = essentialProperty("Rows");
if (p.numKeys > 0){
  n = p.nearestKey(time).index;
  t = p.key(n).time;
  if (time < t){
    linear(time, t-fDur, t,100, 0);
  }else{
    linear(time, t, t+fDur, 0, 100);
  }
}else
  value
Roland Kahlenberg
Legend
June 28, 2022

AE has a pre-installed Animation Preset (ffx) that auto-fades based on the layer's in-out points. You can specify a duration for the fades - see image below 


There's also the Animation Preset - Opacity Flash - layer markers. This is also useful.
HTH

 

Very Advanced After Effects Training | Adaptive &amp; Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
vasulden
vasuldenAuthor
Participating Frequently
June 28, 2022

many thanks @Roland Kahlenberg ! 

have tried that thing already. But I would like to keep the one layer, with several keyframes and make them animate every time when a new keyframe appears per time. But didn't realize the right parameter to let the expression know which is a range of Start/End points in the term of keyframes, but not the whole layer 

vasulden
vasuldenAuthor
Participating Frequently
June 28, 2022

those hold keys are doesn't belong to Opacity. it might be something random thing, even out of this Comp, even not a slider 🙂

but maybe I'll define my obsession, have tried to make that range of inputted keys to use sort of linear expression as above... 😞 

Mylenium
Legend
June 28, 2022

Same principle:

 

http://www.motionscript.com/design-guide/audio-trigger.html

 

You may of course need to modifiy and adapt it, but your question is way too generic and broad for any specific advice.

 

Mylenium

vasulden
vasuldenAuthor
Participating Frequently
June 28, 2022

thank you so much for the fast response @Mylenium ! 

It might be it, but I've tried to adapt several of these kinds of expressions, but nothing was successful. Same thing with that one, but will try to play around with it and let you know if I get something

Thanks!