What Are After Effects Expressions?

 As you can probably tell if you check out my articles with any regularity I'm a big fan of Adobe After Effects, and we've still only barely scraped the surface of this powerful program. One element we only touched on briefly before is After Effects expressions. But what are expressions anyway?

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 elements 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? Jeez you ask so many questions, alright here's why.

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 a 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.

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

I've made a new composition within After Effects that is 24 frames long and we'll do our action scripting in here. Now remember, unlike action script in Flash (Animate) we can't add action scrip to a composition as a whole. Expressions live within elements in our timeline, and within attributes of those elements. So we'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 lovely little square, I made a red one that's 300 by 300. Now let's do a simple expression to learn how they work.

With my solid selected I'll hit P to bring up it's Position drop down menu in my timeline. Now if I were going to animate this I'd simply click the stop watch to activate keyframes, but to add an expression I'll want to Option or Alt click the stop watch.

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 our timeline also we now have an area we 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 like I mentioned earlier, this will cause our object to move around slightly throughout our animation.

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

The start our expression we're going to type "wiggle" that's telling After Effects we're applying the wiggle expression (duh) 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 our object, so if our frames per second is 30, then putting a 30 in for the value of x will make it that our object moves every frame.

Putting in a 15 at 30fps will result in every other frame moving our object, etc.

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

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

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

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 effecting 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!