• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Fade in/out opacity using a checkbox

New Here ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

Hey!

 

I am new to expressions and I am having trouble solving this problem: 

 

I have a checkbox control set to the opacity of a layer. When the checkbox is checked, the opacity is 100%, when it is unchecked, it is set back to 0%.

 

Now I want to keyframe the expression along the timeline. Each time the checkbox is set to "ON", I want the opacity to fade in over one second from 0 to 100. When the checkbox is set back to "OFF", the opacity fades out from 100 to 0.

 

Thank you!

 

if(comp("Checkbox_Comp").layer("Controller").effect("switcher")("Checkbox") == 0 ) {0} else {100}

 

TOPICS
Error or problem , Expressions

Views

211

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 31, 2022 Aug 31, 2022

This may work, unless you have nested comps with non-zero start times for the precomp layers:

cb = comp("Checkbox_Comp").layer("Controller").effect("switcher")("Checkbox");
n = 0;
if (cb.numKeys > 0){
  n = cb.nearestKey(time).index;
  if (time < cb.key(n).time)n--;
}
if (n > 1){
  t = time - cb.key(n).time;
  if (cb.value){
    linear(t,0,1,0,100);
  }else{
    linear(t,0,1,100,0);
  }
}else
cb.value*100

Votes

Translate

Translate
LEGEND ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

A for() loop iterating through the keyframes and then determining the imaginary span could probably do it. You'd figure out the closest keyframe, determine the times and values using valueAtTime() and then apply a linear(time,startTime,endTime,valueA,valueB). Here's a similar example and the discussion on it:

 

https://community.adobe.com/t5/after-effects-discussions/advanced-aftereffects-question-keyframe-abl...

 

Check it out and modify as needed.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

This may work, unless you have nested comps with non-zero start times for the precomp layers:

cb = comp("Checkbox_Comp").layer("Controller").effect("switcher")("Checkbox");
n = 0;
if (cb.numKeys > 0){
  n = cb.nearestKey(time).index;
  if (time < cb.key(n).time)n--;
}
if (n > 1){
  t = time - cb.key(n).time;
  if (cb.value){
    linear(t,0,1,0,100);
  }else{
    linear(t,0,1,100,0);
  }
}else
cb.value*100

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

LATEST

Hello Mylenium, Hello Dan!

Thanks for the quick reply! Dan's expression was exactly what I was looking for. It works perfectly and saved me a lot of work!

 

Best
iamloron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines