Expressions

After Effects built-in variables, properties, functions, and syntax

Overview

After Effects expressions use JavaScript syntax to automate animation, link properties, and create dynamic effects. Below are the most useful variables, properties, functions, operators, and syntax for writing expressions.

Tips

  • • Use value to refer to the current property.
  • • Use time for time-based animation.
  • • Most math and logic from JavaScript is available.
  • • Use wiggle() for random movement.
  • • Use loopOut() and loopIn() for looping keyframes.

Variables

Name / CodeExampleDescription
timetime * 30Current composition time in seconds.
valuevalue + 10Current property value.
indexthisComp.layer(index + 1)Layer index in the comp.
thisCompthisComp.widthReference to the current composition.
thisLayerthisLayer.opacityReference to the current layer.
parentparent.positionReference to the parent layer.

Properties

Name / CodeExampleDescription
rotationrotation + 45Layer rotation property.
opacityopacity * 0.5Layer opacity property.
positionposition + [100,0]Layer position property.
scalescale * 2Layer scale property.
anchorPointanchorPoint + [0,50]Layer anchor point property.

Functions & Methods

Name / CodeExampleDescription
comp(name)comp("Main")Gets a composition by name.
layer(name or index)layer("Logo")Gets a layer by name or index.
wiggle(freq,amp)wiggle(2,50)Randomly wiggle a property.
seedRandom(seed, timeless)seedRandom(123,true)Sets the seed for randomization.
loopOut()loopOut()Loops keyframes after last keyframe.
loopIn()loopIn()Loops keyframes before first keyframe.
ease(t, tMin, tMax, value1, value2)ease(time,0,1,0,100)Interpolates between two values over time.
linear(t, tMin, tMax, value1, value2)linear(time,0,1,0,100)Linear interpolation between two values.
clamp(val, min, max)clamp(x,0,100)Restricts a value to a range.
toComp([x, y])toComp([0,0])Converts layer space coordinates to comp space.
toWorld([x, y])toWorld([0,0])Converts layer space coordinates to world space.
lookAt(from, to)lookAt(thisLayer.position, target.position)Returns orientation from one point to another.
random(min, max)random(0,100)Returns a random number between min and max.
Math.sin(x)Math.sin(time)Sine function from JavaScript Math.
Math.cos(x)Math.cos(time)Cosine function from JavaScript Math.
Math.abs(x)Math.abs(x)Absolute value.
Math.floor(x)Math.floor(time)Rounds down to nearest integer.
Math.round(x)Math.round(time)Rounds to nearest integer.
Math.max(a, b)Math.max(a,b)Returns the larger of two values.
Math.min(a, b)Math.min(a,b)Returns the smaller of two values.
Math.random()Math.random()Random number between 0 and 1.

Operators

Name / CodeExampleDescription
+, -, *, /a + bMath operators: add, subtract, multiply, divide.
==, !=, >, <, >=, <=x >= 10Comparison operators.
&&, ||, !a && bLogical operators: and, or, not.

Syntax & Statements

Name / CodeExampleDescription
if (cond) { ... } else { ... }if (x > 10) { y = 1; }Conditional logic.
// comment// This is a commentSingle-line comment.
for (var i=0; i<10; i++) { ... }for (var i=0; i<10; i++) { x += i; }For loop.
while (cond) { ... }while (x < 100) { x++; }While loop.
var x = 10;var y = 5;Variable declaration.