Skip to main content
Participant
March 10, 2021
Answered

[Essential Graphics][Stuck with JavaScript][Sadness]

  • March 10, 2021
  • 1 reply
  • 323 views

After Effects newbie here. Feel free to correct me 🙂
What I'm trying to do:
a) Create an Essential Graphic that allows me to drop different amounts of text in it and to animate the vertical position of the textbox based on the amount of text I have.
Since Essential Graphics template does not allow to keyframe things, I have to somehow automate the scrolling amount and scrolling speed of the text box (maybe I should use responsive markers for the latter part, not sure).
What I came up with:
I referenced this and this to come up with this:

var totalLetters = text.sourceText.length;
var maxLetters = 140;

if (totalLetters > maxLetters) 
  {
    var pos1 = transform.yPosition.key(1).time;
    var pos2 = transform.yPosition.key(2).time;
    var ffs1 = transform.yPosition.valueAtTime(pos1);
    var ffs2 = transform.yPosition.valueAtTime(pos2);
    ffs2 = ffs1 - totalLetters*0.7;
    }

 

1.The problem is, it does not seem to store the yPosition of the keyframe properly and ends up doing basically nothing.
2.And the second part that I have no idea how to solve with a script, is the part where I need to come up with a way to calculate correctly the amount of pixels the textbox needs to move in order to always keep 140 letters displayed and not just have them slide into a weird position (hope you understand what I mean by it). Basically, the scrolling needs to stop if there's less than 140 letters displayed.

 ffs2 = ffs1 - totalLetters*0.7;


Any suggestions and solutions would be much appreciated 🙂

 

This topic has been closed for replies.
Correct answer Mylenium

There's plenty of info on how to do all of this with sourceRectAtTime() here on this forum. just do a search. And of course the text won't scroll because there is nothing driving it based on time. All you are doing is calculating some static values. You need at least some interpolator like linear(time,key1,key2,pos1,pos2) in there or multiply time with whatever factor you calculate instead of just the text length. I suggest you approach this more broadly and actually read up on some expression basics. It's a bit more complex than what you have here.

 

Mylenium

1 reply

Mylenium
MyleniumCorrect answer
Legend
March 10, 2021

There's plenty of info on how to do all of this with sourceRectAtTime() here on this forum. just do a search. And of course the text won't scroll because there is nothing driving it based on time. All you are doing is calculating some static values. You need at least some interpolator like linear(time,key1,key2,pos1,pos2) in there or multiply time with whatever factor you calculate instead of just the text length. I suggest you approach this more broadly and actually read up on some expression basics. It's a bit more complex than what you have here.

 

Mylenium

OFIX_AAuthor
Participant
March 11, 2021

Thank you so much for the reply! I'll do just that and let you know if I were able to solve this 🙂