Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Making a null toggle another layer's opacity… With a fade

  • Making a null toggle another layer's opacity… With a fade

    Posted by Jerome Laville on April 10, 2022 at 8:21 pm

    Hi,

    I have a few specific “states” needed in my composition, and I’m using a Slider control on a Null to toggle those states.

    A slider value of “1” toggles the opacity of layers A, B and C to 100, the others to 0.
    A slider value of “2” toggles the opacity of layers D, E and F to 100, the others to 0.
    A slider value of “3” toggles the opacity of layers G, H and I to 100, the others to 0.

    I’m using keyframes on the Null to change the slider value between 1, 2 and 3 depending on which set of layers I need to be at full opacity.

    However I would like for the change happening at each toggle to be eased over 1 second, rather than happen abruptly.

    I feel I am close with this expression (added to each layer’s opacity), however using ‘time’ doesn’t quite cut it because, I believe, as the expression is constantly recalculated, the fade is restarted at every frame.

    starttime = time;

    endtime = starttime + 1;

    if(thisComp.layer("Null").effect("Slider Control")("Slider") ==1) {easeOut(time,starttime,endtime,0,100)} else {(time,starttime,endtime,100,0)};

    Many thanks.

    Jerome Laville replied 2 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 10, 2022 at 11:31 pm

    If I understand what you’re after, it’s a little more complex. This doesn’t account for all possibilities, but it should get you pretty close (update myNum for each group):

    myNum = 1;

    easeTime = 1;

    s = thisComp.layer("Null").effect("Slider Control")("Slider");

    if (s.numKeys > 1){

    n = s.nearestKey(time).index;

    if (time < s.key(n).time) n--;

    if (n > 0){

    if (s.key(n).value == myNum){

    ease(time,s.key(n).time,s.key(n).time+easeTime,0,100);

    }else{

    if (n > 1){

    if (s.key(n-1).value == myNum){

    ease(time,s.key(n).time,s.key(n).time+easeTime,100,0);

    }else{

    0;

    }

    }else{

    0;

    }

    }

    }else{

    0;

    }

    }else

    s.value == myNum ? 100 : 0

  • Jerome Laville

    April 11, 2022 at 8:22 am

    That’s… Exactly what I’m after.

    Dan, thank you so much for your time and effort — it’s much appreciated.

    Have a great day.

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