Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help translating from Legacy ExtendScript to JavaScript

Explorer ,
Oct 30, 2024 Oct 30, 2024

Hello, I recently upgraded my AfterEffects from a really old version, and some of the code that I had previously used in a lot of templates and projects is now no longer working. After some troubleshooting, I found that I can make it work if I switch my project to use Legacy ExtendScript instead of JavaScript. Is anyone able to help me translate my code so that I can use it in a JavaScript project?

 

(I don't even remember where the original code for this came from, I just found it somewhere on an old internet forum.)

 

var L = thisLayer;
var easing = 5 + thisComp.layer("Controller").effect("Easing")(1); // Slider determines easing amount, 1 is linear
var val = value;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (time < key(n).time) n--;
  if (n > 0 && n < numKeys){
    val = easeValues(key(n).time,key(n+1).time,key(n).value,key(n+1).value,easing);
  }
}
val

function easeValues(startT, endT, startV, endV, ease) {
var dur = endT - startT
normalizedEasing =(Math.ceil(ease/2) * 2)-1;
var easedTime = easeTime(time - startT, 0, 100, dur);
return linear(easedTime, 0, 100, startV, endV);
}
function easeTime(t, b, c, d) {
if ((t/=d/2) < 1) {
return c/2*Math.pow(t, normalizedEasing) + b;
} else {
return c/2*((t-=2)*Math.pow(t, normalizedEasing -1) + 2) + b;
}
}

 

Thank you, and have a nice day!

TOPICS
Expressions , How to , Scripting
534
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 30, 2024 Oct 30, 2024

Maybe try placing the functions at the beginning of the code.

function easeValues(startT, endT, startV, endV, ease) {
    var dur = endT - startT;
    normalizedEasing =(Math.ceil(ease/2) * 2)-1;
    var easedTime = easeTime(time - startT, 0, 100, dur);
    return linear(easedTime, 0, 100, startV, endV);
}
function easeTime(t, b, c, d) {
    if ((t/=d/2) < 1) {
        return c/2*Math.pow(t, normalizedEasing) + b;
    }
    else {
        return c/2*((t-=2)*Math.pow(t, normalizedEasing -1) + 2) +
...
Translate
Advocate ,
Oct 30, 2024 Oct 30, 2024

Maybe try placing the functions at the beginning of the code.

function easeValues(startT, endT, startV, endV, ease) {
    var dur = endT - startT;
    normalizedEasing =(Math.ceil(ease/2) * 2)-1;
    var easedTime = easeTime(time - startT, 0, 100, dur);
    return linear(easedTime, 0, 100, startV, endV);
}
function easeTime(t, b, c, d) {
    if ((t/=d/2) < 1) {
        return c/2*Math.pow(t, normalizedEasing) + b;
    }
    else {
        return c/2*((t-=2)*Math.pow(t, normalizedEasing -1) + 2) + b;
    }
}
var L = thisLayer;
var easing = 5 + thisComp.layer("Controller").effect("Easing")(1);
// Slider determines easing amount, 1 is linear
var val = value;
if (numKeys > 0){
    n = nearestKey(time).index;
    if (time < key(n).time) n--;
    if (n > 0 && n < numKeys){
        val = easeValues(key(n).time,key(n+1).time,key(n).value,key(n+1).value,easing);
    }
}
val;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 30, 2024 Oct 30, 2024

LOL That's a super simple fix! Works like a charm. Thanks for the help. 😛

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2024 Oct 30, 2024
LATEST

This is helpful if you need to convert any other legacy code to the new engine:

https://helpx.adobe.com/after-effects/using/legacy-and-extend-script-engine.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines