AE Expression Terminology 101


The Expression Language

After Effects uses JavaScript engine to output their expressions. Below we will go over some terminology, to better understand writing expressions.

What Is JavaScript?

Answer: JavaScript is a programing language that tells After Effects a set of instructions through Statements. Such as wiggle, change color, move up etc…

How Do Statements Work?

Statements read Left to Right. These Statements are composed of: Values (stored in Variables), Functions, Expressions… It uses the Dot Notation to separate objects and the layers attributes. Usually end with a Semicolon ; and can be one or multiply lines.

When writing Statements it is Best Practices to use WhiteSpace between characters to increases legibility. Example: wiggle(4,5); vs. wiggle (4, 5);

Use Comments on Statements for complex coding as future reference. Think of them as notes. They do not hinder any coding and are just for your eyes. One way to write a comment is to begin with Typing //. After Effects gives it the code color green (see example below). You can also type /* This is is a comment */

After Effects Expression Note Example

What is a Variable?

Similar to Algebra back in school. A Variable is an object that stores particular values/data. Example: x = 4. The name must begin with a letter and is Case Sensitive. Never use spaces when naming, and always follow camelCase style in naming.

What are Value Types?

  • Numbers
    • These are numeric values with fractions written as decimals
    • Example: 1, 4.5, 3.980
  • Strings
    • Used to represent text, written by enclosed double or single quotes
      • ‘text’ or “text”
    • They can be divided, multiplied or subtracted but can be added (+)
      • ‘cat’ + ‘dog’
  • Boolean
    • Only have two sets of values:
      • True or False
      • Yes or No

What is camelCase?

camelCase is code styleguide for naming Variables and Functions. The first character of the first word is lowercase. Then the next word the first character is capitalized. Ex: valueAtTime ( )

What is a Function?

A Function is code that tell After Effects to do a particular task. It starts with its name and calls the function by using parentheses ( ) to preform the task. Inside ( ) are the Parameters of the function. When Parameters are given values these are then called its Arguments.

  • Example: The wiggle function. It is written: wiggle (4, 3);
    • Parameters of this function:
      • First is Frequency: It’s speed per second
      • Second is Amplitude: It’s distance
    • Frequency value is 4. Which means, move 4x/per sec.
    • Amplitude value is 3. Move three pixel up/down left and right.
      • Values 4, 3 are the Arguments in the wiggle function.

Note: Not all Functions need to have values put into the ( ) for them to work. Example: LoopIn ( )

Examples of After Effects Methods /Functions and their Parameters
  • random (minValue, maxValue)
  • wiggle (freq, amp, octave, amp_mult, time)
  • loopIn (type, numKeyframes)
  • velocityAtTime (t)
  • For more in-depth list visit the Adobe-Expression Language Reference.

What is a Dot Notion?

A Dot Notion “.” is used to separate the objects and the layer’s attributes. Think of it as a connecting tool like the word and and the in english.

  • Example: Create 2 Shape Layers
    • 1 Triangle Layer
    • 1 Square Layer
  • On the Square Layer: Open arrow under Transform and click on the stop-watch icon on the Rotation. Then use the pick-whip and link to the Rotation of the Triangle.
    • This layer will now have an expression written thisComp.layer("Triangle").transform.rotation
    • Which means, follow This Composition of the Layer name Triangle and Transform the Rotation value to match it.
    • Set two key frames on the Triangle Layer and watch it work.

Layer Objects Attributes

  • width: returns in pixels same as “source.width”
  • height: returns number of height of the layer “source.height”
  • index: returns a number of the layer within the composition.
  • Under the column sign # in the time line
  • Note: .index: returns the number of this layer