help to animate an lower thirds that's positioned by expressions I'm new to using expressions in after effects and I've also hardly touched Java before.  However using some online tutorials and common sense, I managed to create a lower thirds title graphic yesterday, the java is used to change it's position based on how much text is written inside.  The title graphic bleeds off to the left of the screen, so when text is written on it, it moves left or right to match the length of text.  I've included the code below.

s =thisComp.layer("Header title");
x = s.sourceRectAtTime(time-s.inPoint,true).width;

subl =thisComp.layer("Sub title");
subt = subl.sourceRectAtTime(time-subl.inPoint,true).width;

text = Math.max(subt, x) -100;

max = 659.4;
m = Math.min(max, text);

[m, 871]


So with a little bit of text:


With more text:


Where I'm struggling is I want to make this into an animated motion graphic, where the graphic just slides in and out at the right time.  However, if there's less text, it's position is further out the frame and it takes longer to slide in - which means that it's out of sync with other parts of the animation.  I'm not worried about consistent speed, I just want it to appear in at the same time as it has to match other animations.  The only way I can see this happening accurately is by further encoding, where it gets a little beyond me!

I tried animating using if expressions dependant on the time function, but this didn't create a transition, the graphic jumped instantly from point to point.  I can't find anything on creating keyframes in java either so not sure the best way to do this.

Really appreciate any help to put me on the right track.
There are some built-in functions just for this purpose. You'll find them in the interpolation folder in the expression drop-down. The simplest is the linear() function:

linear(t, value1, value2)


This function interpolates in a linear fashion between value1 and value2 based on the value of t, where 0 ≤ t ≤ 1. So if t=0 the function returns value1 and if t=1 it returns value2. It can also take five parameters, in the form

linear(t, tMin, tMax, value1, value2)


in this form, instead of using the range 0-1 for t it uses the range tMin to tMax.

Along with linear() there are also ease(), easeIn() and easeOut(). These interpolate with easing - meaning the animation slows down at the beginning or end, or both.

So in your example you could add this before the last line:

startTime = inPoint; //if you want the animation to start at the start of the layer
m = ease(time-startTime, 0, animationLength, 0, m)


this will smoothly animate from the layer's in-point for animationLength seconds to the calculated position.

Oh, BTW it's Javascript not Java. They are completely different languages. As they say, Java and Javascript are similar in the same way that "car" and "carpet" are similar.