You opened After Effects to build a timer or digital clock animation, pasted an expression you found online, and got a red error. If you're on After Effects 2022 or newer, that error is almost certainly the JavaScript engine conflict. This page gives you the working expression, explains what each variable does, and shows you the fix.
- Copy the expression below and paste it into Source Text (Alt+click the stopwatch)
- If you get an error: File > Project Settings > Expressions > switch to Legacy ExtendScript
- Font: Digital Dismay (free, install before opening AE)
The Digital Clock Expression
Paste this into the Source Text expression field of your text layer:
rate = 1;
clockStart = 0;
function timerg(n) {
if (n < 10) return "0" + n;
else return "" + n;
}
clockTime = Math.max(clockStart + rate * (time - inPoint), 0);
t = Math.floor(clockTime);
min = Math.floor((t % 3600) / 60);
sec = Math.floor(t % 60);
min + ":" + timerg(sec);Two variables control the entire behavior:
| Variable | What it does | Example |
|---|---|---|
rate | Speed multiplier. 1 = real time, 2 = double speed, -1 = countdown | Set to -1 for a countdown |
clockStart | Starting value in seconds. 0 = starts at 00:00, 60 = starts at 01:00 | Set to 120 to start at 02:00 |
The rest of the expression handles the math: timerg() pads single digits with a leading zero so you get 01:05 instead of 1:5. Math.max(..., 0) stops the clock at zero if you're counting down. inPoint anchors the clock to wherever the layer starts in the timeline, so you can drop it anywhere in your comp without adjusting variables.
For a countdown, set rate = -1 and clockStart to your total seconds. A 3-minute countdown: clockStart = 180; rate = -1;. If you need a dynamic countdown timer with more control over start and end frames, that covers the keyframe-based approach alongside expressions.
How to Fix the JavaScript Engine Error (After Effects 2022+)
This is the most common reason expressions fail on newer versions of AE. After Effects 2022 switched the default expression engine to JavaScript, but most expressions you'll find online, including this one, were written for Legacy ExtendScript. The engines are not compatible.
The fix:
- Go to File > Project Settings
- Click the Expressions tab
- Change Expression Engine from JavaScript to Legacy ExtendScript
- Click OK
Your expression starts working immediately. This is not a workaround. Adobe kept Legacy ExtendScript in the software because the entire ecosystem of existing expressions depends on it. Switching for a single project file has no downsides.
Other errors you might see:
| Error | Cause | Fix |
|---|---|---|
| "Unable to parse expression" | Curly quotes (") instead of straight quotes (") from copy-paste | Retype the quotation marks manually |
| Clock jumps or shows wrong time | Layer in-point is before frame 0 | Move the layer's in-point to frame 0 or later |
| Font looks wrong | Digital Dismay installed while AE was open | Close AE, reopen, reselect font in Character panel |
| Expression runs in preview but breaks in render | Project not saved with Legacy ExtendScript setting | Save project after changing engine, re-render |
How to Set Up the Text Layer
Open the expression editor by expanding your text layer in the timeline: Text > Source Text, then Alt+click the stopwatch icon next to Source Text. Paste the expression and click anywhere outside the field to apply.
Before you paste, set the Paragraph panel alignment to right-justify. This prevents the colon from drifting left as the digit count changes from single to double digits. Type 88:88 as placeholder text first so AE reserves the full digit width.
How to Build the LED Display Look
The expression gives you a working clock. The layer structure is what makes it look like a real LED display rather than plain text.
Layer stack (top to bottom):
- Active clock layer: your expression-driven layer, full opacity, bright color (blue works well on dark backgrounds)
- Ghost layer: duplicate of the clock layer, expression disabled, static
88:88, gray color at 15-25% opacity. This mimics the unlit segments on a real LED display. - Glow layer: another duplicate, moved to the bottom. Apply Effect > Blur and Sharpen > CC Radial Fast Blur, Amount around 30-50, color darkened. This creates the soft light bleed you see on real LED panels.
A dark background makes the whole composition read significantly better. With just the active layer and the ghost layer (skipping the glow), you already get a clean, readable result.
The same layer separation logic applies when you animate a PNG logo in After Effects: isolating each visual element into its own layer gives you precise control without touching the original asset.
Adjusting the Clock Behavior
Start mid-comp: Drag the layer's in-point to any position in the timeline. The clock starts counting from zero at that point, no variable changes needed.
Freeze at a specific time: Add a Slider Control effect to the layer, connect rate to the slider, and keyframe it to 0 at the frame where you want to freeze.
Add hours: Insert hrs = Math.floor(t / 3600); before the min line and prepend hrs + ":" to the output string. For most motion graphics running under an hour, the MM:SS format is sufficient.
Text box sizing: If your clock text shifts the surrounding layout as digits change width, auto-resizing text boxes with sourceRectAtTime solve this with the same Alt+click expression workflow.
Once the expression engine setting, the font, and the layer stack are in place, you have a fully keyframe-free clock you can reuse across projects by changing two variables.
Comments (0)
Sign in to comment
Report