Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Update expression for newer JavaScript engine?

  • Update expression for newer JavaScript engine?

    Posted by David Cabestany on July 30, 2021 at 4:03 pm

    Anyone can help to update this expression to work with the newer expression engine? It works fine with legacy but then some other expressions in different parts of my project stop working.

    Thanks in advance.

    Btw, this expression is to create a counter that goes into the thousands and automatically adds a comma and places it in the correct location.

    —————-

    var num = thisComp.layer(“xp”).effect(“counter”)(“Slider”);

    num = Comma(num);

    [num]

    function Comma(number)

    {

    number = ” + Math.round(number);

    if (number.length > 3)

    {

    var mod = number.length % 3;

    var output = (mod > 0 ? (number.substring(0,mod)) : ”);

    for (i=0 ; i < Math.floor(number.length / 3); i++)

    {

    if ((mod == 0) && (i == 0))

    output += number.substring(mod+ 3 * i, mod + 3 * i + 3);

    else

    output+= ‘,’ + number.substring(mod + 3 * i, mod + 3 * i + 3);

    }

    return (output);

    }

    else return number;

    }

    David Cabestany replied 3 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    July 30, 2021 at 4:28 pm

    I believe the JavaScript engine doesn’t allow you to end an expression with a function definition, so you might try moving the function to the top.

  • David Cabestany

    July 30, 2021 at 6:41 pm

    oh may gaaaaaaaaaad! That was it, thank you so much Dan the man!

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