Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Linking keyframes position X values to slider values

  • Linking keyframes position X values to slider values

    Posted by Daniel Kamhaji on August 25, 2021 at 11:09 pm

    Hello!

    I’m sure this is simple for the experts here and I would love the help. I have searched here and google but have not found a helpful thread yet.

    I’m making a search field text animation for a title that needs to be customizable.

    and if the text is longer then the search box it will animate left as long as it needs to have the last word end up at the end of the search field. so I have 2 keyframes set.

    The first keyframe is locked, the type should start there. and the second keyframe value is the one that I would want attached to a slider so the editor can adjust depending how far the type has to move to fit.

    so in summery, locking the position of the first keyframe where its at. but attaching the x position of the second keyframe to a slide value.

    Any help would be greatly appreciated!

    Daniel Kamhaji replied 5 years ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    August 26, 2021 at 1:38 am

    There are a lot of variables in something like this and I don’t know that this will work for you, but if you set the slider up as an X offset from the 2nd keyframe, something like this might work for you (and should maintain any easing you have set up on the keyframes):

    s = effect("Slider Control")("Slider");

    x1 = valueAtTime(key(1).time)[0];

    x2 = valueAtTime(key(2).time)[0];

    d = x2 - x1;

    xCur = value[0] - x1;

    x = x1 + (xCur/d)*((x2+s)-x1);

    [x,value[1]]

  • Daniel Kamhaji

    August 26, 2021 at 3:18 pm

    Hey Dan,

    Thanks for your reply!

    I’m trying to plug this in and getting an error.

    error on line 3: property or method named ‘0’ in class ‘Number’ is missing or does not exist.

    I’m supposing this expression would plug in the layer’s Pos X.

    I also have a slider effect in the same layer with the default effect name..

    Thanks for the help!

    I did get a total hack kinda working in case..

    I duplicated the layer, and referenced the 2 keys with a variable.. and remapped their values with a linear expression on the duplicated layer…. and those values attached to a slider.

    im hoping to get your cleaner version working.

    Also for future use,

    how would I edit yours above if there are more keys.

    im not exactly understanding the lingo(magic) behind it.

    Say there was 4 keys and I wanted to attach the slider to anyone of those keys?

    Thanks Again!

  • Dan Ebberts

    August 26, 2021 at 5:02 pm

    If you have dimensions separated, then it would be like this:

    s = effect("Slider Control")("Slider");

    x1 = valueAtTime(key(1).time);

    x2 = valueAtTime(key(2).time);

    d = x2 - x1;

    xCur = value - x1;

    x1 + (xCur/d)*((x2+s)-x1);

  • Daniel Kamhaji

    September 1, 2021 at 4:06 pm

    Thank you so much,

    this worked like a charm!

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