What Are After Effects Expressions?

Adobe After Effects


An After Effects expression is similar to a line of computer code, or action script within Flash (now Adobe Animate.) Much like computer code or action script an expression is some type of formula telling After Effects to do something specific. Unlike action scripting, however, expressions live within an element's attributes, like their scale or rotation.

So what's the point of using an expression? Well, expressions can work in any number of ways, the two best examples though are to animate something and to affect something's animation. Why use an expression to animate instead of using keyframes?

When and How to Use Expressions

Say you have a ball moving across the screen from left to right, but you also want that ball to wiggle. Rather than going in by hand and doing that, or applying an effect and giving it lots and lots of keyframes, we can simply apply a wiggle expression to it.

So we'll only have our two keyframes saying to go from left to right, plus the expression telling it to wiggle. It keeps things nice and organized as well as easily changeable. Rather than having to redo hundreds of keyframes if we want our wiggle to be more extreme we can simply change the expression. So we're animating our object in two ways, using keyframes and using an expression.

Another common example of how expressions can work in After Effects is by affecting a piece of animation without actually animating it. You can write an expression that says as time progresses our animation will become more extreme or less extreme.

If we have an effect of pulsing light, we can apply an expression to it that says as our animation plays the pulsing light gets more and more dramatic, without actually having to go in and animate that effect magnifying. Here, we're not animating using an expression, but affecting a piece of animation with the expression.

A Wiggle Expression as An Example

Let's do a simple wiggle expression as an example to get an understanding of how they work.

You'll make a new composition within After Effects that is 24 frames long and you'll do your action scripting in there. Now, remember, unlike action script in Flash (Animate) you can't add action script to a composition as a whole. Expressions live within elements in your timeline and within attributes of those elements. So you'll need to make something to apply the expression to.

Let's make a simple square using solids. Hit Command+Y and make yourself a little square. Now let's do a simple expression to learn how they work.

With your solid selected, hit P to bring up its Position drop-down menu in your timeline. If you're going to animate it, you'd simply click the stopwatch to activate keyframes, but to add an expression you'll want to Option or Alt+click the stopwatch.

This will turn the Position attribute into a new little drop-down menu, adding Expression: Position below it. You'll see over to the right in your timeline an area you can type in that currently says "transform.position."

This text field here is where we type out all of our expressions. A nice simple expression is the wiggle expression as mentioned earlier — this will cause your object to move around slightly throughout your animation.

The wiggle expression is set up like this: wiggle(x,y).

To start your expression you're going to type "wiggle" — that's telling After Effects you're applying the wiggle expression followed by the values in the parenthesis which is telling After Effects when and how much to wiggle.

X stands for how many times per second you'd like After Effects to move your object, so if your frames per second is 30, then putting a 30 in for the value of X will make it so that your object moves every frame. Putting in a 15 at 30fps will result in every other frame moving your object, etc.

The Y value stands for how much you want your object to move. So a Y value of 100 will move your object 100 points in any direction and a Y value of 200 will move your object 200 points in any direction.

So a completed wiggle expression will look something like this: wiggle(15,250).

Now you'll see your square wiggling around your stage when you hit play, but you haven't applied any keyframes at all. You can even go in and do the example originally cited, and add in keyframes of your square moving from left to right along with your expression.

Rounding out Expressions

So in summary, an After Effects expression is a piece of text, much like a piece of code, applied to a property of an element that is affecting that property. They work in a myriad of ways and have a wide range of uses, but much like code, they are finicky to spelling and punctuation mistakes, so be sure to double-check them as you type.