CONTENTS

Introduction

When to Use Expressions

What Is an Expression?

Adding Expressions

The Pick Whip

Vectors and Dimensions

Ranges of Values

Interpolation Methods

Objects

Global Objects

The Default Object

Methods and Attributes

Vector Math

an example

OTHER MATERIAL

Geometry

Tables

Project Index

HOME

Introduction to Expressions

Before we really focus on Expressions, we should talk a little about relationships in After Effects in general. As far as I know, there are five main ways to establish relationships between elements in After Effects:

Brute Force: you simply keyframe things in a way that makes them look like they’re related, even though there’s no essential connection between them. This is perhaps the most common kind of relationship, and is extremely flexible, but can be tedious to set up and to modify later.

Pre-composing: You can place a number of layers together in one comp, and then use that comp as a layer in a second comp. This really acts like grouping in other programs, a way to treat several elements as a single unit.

Parenting: New to After Effects 5.0, Parenting lets you establish hierarchical relationships without pre-composing. In a parent-child relationship, any transformations applied to the parent immediately cascade to the child; changes to the child do not flow ‘upstream’ to the parent, however.

Motion Math: Like Expressions, Motion Math is a simple programming environment within After Effects. Motion Math scripts can create keyframes for your layer based on values from another layer or property. For instance, you could use Motion Math to have one layer mimic another’s position changes. Unfortunately, ‘relationships’ created via Motion Math are temporary, and only reflect the conditions at the time the script is executed. Afterwards, changes to one layer will not be reflected in the other layer, unless the script is re-applied.

Expressions: Expressions are similar to Motion Math, but maintain ‘live’ relationships. While Motion Math scripts simply leave behind a set of keyframes, Expressions remain attached to your parameter, and work alongside any existing keyframes. With Expressions, changes to one layer may be reflected in another, long after the Expression was initially applied.

Of these types of relationships, Expressions may be the most powerful, but also can be the toughest to create, with the least assistance from After Effects.

When to Use Expressions

When you want a live link. As discussed above, expressions are an excellent way to create a live link between layers. Any situation where you're tempted to copy and paste keyframes from one layer to another is an ideal candidate for an expression.

When you want to copy just one parameter from a parent. Sometimes, you want to copy values from just one parameter of a layer, rather than a full parent-child relationship. For instance, in the two animations below, the top two layers have a parent-child relationship, while the bottom two layers are connected by an expression attached to the yellow layer’s position parameter. Notice that the parented layer follows both the position and rotation of the green layer, while the expression-controlled layer follows only the position. It doesn’t rotate because we did not apply an expression to its rotation parameter.

For ‘automatic’ animation. You can animate any parameter without a single keyframe by applying an expression whose results vary over time. For instance, in this movie, the layer’s scale is set to oscillate in a sine wave pattern driven by time:

To add randomness to a parameter. You can write a simple expression that takes your parameter’s existing keyframes, and wiggles the values slightly. This is an excellent use of expressions, because it preserves your original keyframes. You could accomplish similar results with The Wiggler (included with the Production Bundle), but it would create a zillion keyframes, overwriting your original keyframes. With an expression, you could simply disable the expression and return anytime to your original keyframes.

When Not to Use Expressions

Anytime you can avoid them.

Seriously. If there’s another way to accomplish what you need to do, that’s very likely the better way. After Effects has many powerful tools and features, each of which is very well designed for specific tasks. You wouldn't, for instance, want to use expressions in a situation where you could just use parenting. The expressions would be a lot more work to set up and maintain.

Don't fall into the trap of 'when you have a hammer, everything looks like a nail.' Expressions are a terrific tool, but they're not always the best tool.

  NEXT

Entire contents © 2001 JJ Gifford.