5 After Effects Expressions That’ll Make You a Hero

If Batman used After Effects, he’d definitely use expressions. (He’d also have a special UI brightness setting labeled Really Dark, but that’s a different topic.)

Let me explain.

Whichever flavor of Caped Crusader you prefer, it’s fair to say he’s best known for the nifty gadgets he calls upon to get the job done. Batman doesn’t climb stairs. He Bat Grapples to the rooftop. And he knows better than to fistfight Superman. Instead, he shows up with a kryptonite spear.

So if you sat him down in front of After Effects, you wouldn’t see him brute-forcing a bunch of keyframes around. He’d streamline his animation workflow with expressions. (Or he’d get Lucius or Alfred to do it, but that’d ruin my metaphor.)

While this article can’t make you the world’s greatest billionaire crime-fighting detective, it can help you on the path to becoming one of the world’s greatest motion designers. Consider it your origin story.

You just need the right tools in your utility belt.

So what is an expression anyway?

Expressions are lines of code (JavaScript) that allow you to control values in Adobe After Effects. They might not sound as cool as a kryptonite spear, but they’re just as effective in the right hands.

Not only can they simplify your motion design workflow, but they open up limitless creative options. They can be amazingly complex, containing paragraphs upon paragraphs of code, or they can be as simple as a single word or number.

But regardless of the size, they all have something in common: they’ll save you a ton of time. And who doesn’t want that super power?

A little goes a long way

If you’re new to this topic, it’s easy to become discouraged if you pick the wrong starting point. We are talking about learning a new language after all.

Sure, you can follow a step-by-step tutorial and copy/paste blocks of text to the parameters of your layers. But this won’t help you to debug and make edits to an expression to get the results you want.

JavaScript is a language with its own syntax. If the expression you create breaks these syntax rules, you won’t get further than a few confusing error messages. So you’re going to need to understand just a little bit about the language before you can leave the Batcave

The good news is that when it comes to expressions, a little bit of knowledge goes a long way. This is the minimum price of admission if you want to work with expressions.

So here are the five essential After Effects expressions that you should start your origin story with. They’re simple, powerful, and will help you get the job done.

1: thisComp

After Effects expressions are all about working with values in an object hierarchy. And in this case, objects are things like the composition, individual layers, and even effects. Objects can contain values, or other objects.

One way to perfectly position objects on screen is to use thisComp in combination with some basic math. Let’s take a look at an example where I want to place a logo in various areas of the frame.

For the first step, I’ll right-click on the position attribute of my logo layer and select Separate Dimensions. This will simply make things easier to animate.

To place the logo directly in the center, I’ll first use this expression for the X position parameter, which is simply taking the width of the comp and dividing it by two. The resulting value will center the anchor point of my logo layer horizontally.

thisComp.width/2

And for Y, I’ll calculate a value that is half of the height of the composition.

thisComp.height/2
Centered logo using After Effects thisComp expression
Centered logo using After Effects thisComp expression.
Separate position values
Dividing thisComp width and height values by two.   

For further precision, I can multiply the comp height and width by a percentage value. Here’s an example where the logo is in the lower left side of the comp.

X Position

thisComp.width*.25

Y Position

thisComp.height*.75
 

The beauty of using these expressions is that they will keep my logo in place even if I change the resolution of the comp. This is very handy when repurposing and exporting different versions for social media platforms. You could even add a similar expression to the Scale parameter to have the logo scale in relation to the size of the comp.

And remember, don’t fear vertical video. To conquer fear, you must become fear.

2: name

Once again, when working with expressions, you’re working with values. Using the term value in a parameter will simply return the parametric value. You can also return the name of the parameter by using name instead of value.

If you put name in the expression box of the Source Text parameter of a text layer, you’ll be able to change the text via the name of the layer. This makes for an incredibly fast workflow, as you can quickly and easily duplicate and rename layers in the timeline panel.

If you’re working with a lot of lower thirds or simply duplicating a lot of text layers, this trick is extremely helpful.

 
If you put name in the expression box of the Source Text parameter of a text layer, you’ll be able to change the text via the name of the layer.

It’s certainly more clunky to have to dive into the textbox of the comp panel to change text. This technique is even more powerful when used with text layers in precomps.

3: loopOut

I use this expression all of the time, as it saves me from doing a lot of tedious keyframe work.

If you’re looking to have an animation repeat, you can always just copy and paste keyframes along the timeline. When you want to make changes, however, you’d naturally have to go back and wrangle all of those same keyframes. (Once again, you’d never catch After Effects Batman doing this.) In situations like these I like to use the loopOut expression.

One great example is when I create map markers with a radar ping effect. It’s as simple as animating the Scale and Opacity parameters of an Ellipse, and then adding loopOut to each parameter. It’s plug and play, automatically cycling the two keyframes. It’s essentially a total of four keyframes, but the animation continues throughout the entirety of the timeline.

 
Using loopOut to create a cycling animation.

You can keep things simple by only using two keyframes per parameter, or get more complex by specifying which keyframes you want to loop. There are even four arguments to control how the animation loops. Again, it defaults to cycle, but you can also set it to continue, offset, and ping pong.

4: time

One of the quickest and easiest ways to generate an animation is to harness the power of time. Time simply generates the number value of each second in the timeline. Keep in mind that this value starts at zero in the beginning of the comp, regardless of the timecode settings.

Once again, pair this with some basic math for some great results. Play around and experiment with multipliers to figure out a value that works for the parameter you’re animating. Use it to slowly change the position or rotation of a layer.

Time also works especially well when you want to drive an animated texture, such as a Fractal or Turbulent Noise effect. Add time*100 to the evolution parameter and away you go.

 
Time works especially well when you want to drive an animated texture.

5: random

I know, it’s practically blasphemous not to have wiggle on the list. Wiggle, the star of expression, is actually an incredibly complex and powerful method. Random, however, is kind of like wiggle’s neglected little brother. It’s certainly more user friendly, only requiring one input value to make it work.

As the name entails, this expression generates a random value for each frame, and the value depends on what you enter as the argument. If you leave it blank, it will automatically randomize between 0 and 1. Enter a value in the parentheses and the parameter will randomize between 0 and the entered value. Enter two values, and it will randomize between those two values.

This is another great expression to quickly generate an animation. I use it often to create flickering opacity transitions. This is as simple as adding the expression below to Opacity, and then keyframing it in and out from 100% Opacity.

random(value, 100)
 
Creating a flicker using random.

I recently created an entire tutorial focusing on how to use the random expression to create flickering opacity transitions, including both keyframe and keyframe-less techniques. Check it out…

Get going

Now that you’re tooled up with the basics, there’s really nothing stopping you. The cool thing is that once you learn a bit, you’ll pick up a collection of expressions that you can tweak and refine for future projects.

Now get out there. Gotham needs you.

To learn more about expressions, check out these resources.

Jason Boone

Boone's short-form documentary work has been featured on National Geographic, Yahoo!, Bing, Fuel, and Current TV. While he's not busy creating tutorials on Adobe Premiere Pro and After Effects, he vlogs about living as an American expat in Paris.