Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger animation at layer endpoint

  • Trigger animation at layer endpoint

    Posted by Seth Geller on April 26, 2021 at 3:03 pm

    Hey all,

    I have a bunch of video clips in an AE timeline, and I want to trigger an animation every time the active layer changes (basically have the background change position and color). Is this possible? How would I go about it?

    My thought is to use a for loop to check for the active layer, and then look to the previous frame, and if the active layer at the current time is different, start the background animation. Something like

    for (var i = 4; i <= thisComp.numLayers; i = i + 1) {
    var compLayer = thisComp.layer(i)
    if (compLayer.active == true) {

    and then something here saying look at the previous frame, and if different, run the background animation and change the color, but I’m unsure how to write that

    There is probably a way easier way to do this (using inPoints maybe?) but I’m not really sure where to go from here or what I should be searching for. Any ideas?

    Seth Geller replied 5 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 26, 2021 at 11:19 pm

    This is an interesting (and tricky) one. What this should give you is that variable “t” will represent how long it’s been since the active layer has changed. You would then use this value to drive your animation. I’m not sure that gives you exactly what you need, but it might give you an idea of how to get there.

    myIdx = 0;

    t = 0;

    for (i = 1; i <= thisComp.numLayers; i++){

    if (i == index) continue; // skip this layer

    L = thisComp.layer(i);

    if (L.enabled && time >= L.inPoint && time < L.outPoint){

    myIdx = L.index;

    break;

    }

    }

    if (myIdx > 0){

    myActive = thisComp.layer(myIdx);

    myTrigger = Math.max(myActive.inPoint,0);

    for (i = 1; i < myIdx; i++){

    if (thisComp.layer(i).enabled && thisComp.layer(i).outPoint <= time){

    myTrigger = Math.max(myTrigger,thisComp.layer(i).outPoint);

    }

    }

    t = time - myTrigger;

    }

    t

  • Seth Geller

    April 27, 2021 at 2:21 pm

    wow, did not expect an answer from THE Dan Ebberts! This works great so far, thank you!

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