After Effects counter

The number one rule of computers? Eliminate tedious tasks through code. If anyone ever asks you to animate a counter inside of a video, instead use the code below (or download the CS6 AE file I open-sourced for you!)

//begin code
startTime = 0; //seconds
endTime = 4; //seconds
beginCount = 1;
endCount = 1000000;
hasCommas = true;
//--dont modify below here----------------
function addCommas ( s ){
if( s.length <= 3 )
return s;
return s.substring(0 , 3) + "," + addCommas(s.substring(3, s.length));
function reverse( s ){
newStr = "";
for(i = s.length-1; i >= 0; i--)
newStr += s.charAt(i)
return newStr;
val = Math.round (linear(time, startTime, endTime, beginCount, endCount) );
if( hasCommas )
reverse (addCommas(reverse( val + "" )))
//end code p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Lucida Grande'} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Lucida Grande'; min-height: 13.0px}

To implement

1) Create a new text layer (Layer —> New —> Text)
2) Click the little triangle to open up the details on your text layer
3) Alt-click on the little timer icon next to “Source Text”
4) Click on Expression: Source Text and paste in the code above
5) Edit the first few lines of the code to match the numbers you want.
6) Style with your typeface of choice. Eliminate “bouncing text” by choosing a mono-spaced typeface, like Inconsolata or courier. Or align the text on the right and watch it “grow” out to the left.
7) After you get your counter working, style it with a faceplate.


1) AE has a built-in counter, but there are limits to the range and the commas are excluded.

2) You could use sliders, but with big numbers, you need sliders attached to sliders as expression controllers.

2) I didn’t write this code, I searched through AE forums and found it that way. I tried to figure out who wrote it originally, in order to give it proper credit, but I can’t track down the first coder. If this is your code, thank you! You’re the best! Find me on Twitter and I’ll properly credit you here.