Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions retaining value

  • Posted by Mo on April 21, 2007 at 10:24 am

    i was wondering how to retain a certain value for use later.. for example, i have 2 layers and layer2’s position is simply following layer1’s position. layer1 is just steady moving from left to right. layer2’s opacity is keyframed to go from 100 down to 25. when it gets to 25, i want it to stop where it is, so basically at the position of layer1 at the time that layer2 reaches opacity of 25.

    so i guess something like this:

    if (thisLayer.opacity.valueAtTime(time) == 25){
    [myPos[0], myPos[1]]
    } else {
    myPos = thisComp.layer(“layer1”).transform.position
    position = myPos
    }

    of course the issue is when opacity is 25, AE doesnt know what myPos is yet. can i declare it somewhere? it seems like the script is read and ran every frame, so putting something at the top is useless since it just gets cleared every frame…

    thanks.
    m

    Dan Ebberts replied 19 years, 1 month ago 3 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    April 21, 2007 at 11:14 am

    The work around is to first ‘read’ all the values the opacity has had between 0 and ‘now’ using a for-loop an valueAtTime()
    like this:


    fd=thisComp.frameDuration/2;
    p=thisComp.layer("layer1").transform.position;
    for (t=0;t 25) {
    p=thisComp.layer("layer1").transform.position.valueAtTime(t); }
    }
    p;

    If the opacity starts to raise again, the layer will jump to the new position.

  • Mo

    April 21, 2007 at 4:11 pm

    thanks! thats idea worked. i coded it in a slightly different way but that idea worked.. however, isn’t the need to do this a bit cumbersome? really no other way, huh?

    thanks again.
    m.

  • Dan Ebberts

    April 21, 2007 at 6:34 pm

    Assuming that 25% occurs at the last opacity keyframe, this should work:

    t = Math.min(transform.opacity.key(transform.opacity.numKeys).time,time);
    thisComp.layer(“layer1”).transform.position.valueAtTime(t)

    Dan

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