When to Use Expressions

What Is an Expression?

Adding Expressions

The Pick Whip

Vectors and Dimensions

Ranges of Values

Interpolation Methods


Global Objects

The Default Object

Methods and Attributes

Vector Math

an example




Project Index


Object References from Scratch

We’ve covered the basics of creating simple expressions with the pick whip. There are times, however, when you can’t or don’t want to use the pick whip. You cannot, for instance, drag the whip to any element not currently visible onscreen, or to attributes such as width or frame_duration (because they don't appear onscreen).

In these cases, you’ll need to build your object references from scratch. This is tougher than using the pick whip, because you need to understand a bit of Javascript syntax, but is easier than it might seem at first. It will help if we first clear up some terminology.

What’s an Object?

An object is just a container. Each object can contain other objects, attributes or methods.

For instance, a comp is a kind of object in After Effects. Each comp can contain other objects, such as layers, or attributes such as duration or width. (We’ll discuss methods later.) All of the After Effects elements you’re familiar with — comps, layers, opacity, etc — either are objects or are contained by objects.

Because objects can contain other objects, locating the element you’re after can involve a series of object identifiers. You should think in terms of hierarchy: start with the largest container and work towards the smallest. In slightly more technical terms, you will always start with a global object.

Global and Non-Global Objects

To identify a property to take data from, you must first start by identifying a global object.

A global object is simply an object that can be referred to without any introduction, anywhere in your expression. Other objects --- the non-global ones — live inside global objects (or inside objects that are inside global objects) and can only be accessed by first naming the objects which contain them.

It may help to think for a minute about street addresses. You cannot, for instance, address a letter to ‘100 Main St.’ and leave it at that. There must be thousands of Main Streets in the US, and the postal service would have no idea which you meant. So, at the very least, you’d need to identify which city your ‘Main St.’ could be found in. You’d also need to specify the state. If you were overseas, you’d even need to specify the country. You don’t need to go further than the country, because they don’t need any introduction — they’re not contained by anything except the Earth itself. Countries therefore can be considered ‘global’ objects.

So, in After Effects, you always need to start with a global object, just like when you address a letter. After Effects’ global objects include:

Global Object Returns Object of Type
this_layer Layer or Light or Camera
this_comp Comp
comp("name") Comp
footage("name") Footage
time Number
value Number

What’s in an Object?

After you’ve identified a global object, you’ll probably want to specify some attribute, method or sub-object belonging to it. But how do you know what your choices are? What’s inside the global object you’ve chosen? You can find this information in the tables I’ve provided here, or in the expressions language reference part of the After Effects User Guide.

First, you need to find out what kind of object you actually have — that is, what kind of object is returned by the specifier you’ve chosen. For instance, ‘this_comp’ returns a comp object (surprise!). Then, you can look in the reference material to see what objects of that type contain. In this example, we’d see that comp objects contain layer objects and attributes such as width or duration (among many other elements).

So, after specifying ‘this_comp’, we could choose a particular layer within the current comp:

this_comp.layer("Solid 1")

This will return the layer named ‘Solid 1’ in the current comp. We could stop here, if we just needed a layer object. Since we typically need a value or vector, however, we probably would repeat the above process, this time looking up what objects, attributes and methods are contained by layer objects.

But first, take a minute to notice the period separating the comp and layer identifiers. This is basic Javascript syntax, a way of specifying that the second object is ‘inside’ the first. To build this kind of reference, you simply start with one object, then a period, then another object (or method or attribute). You can repeat this process as long as necessary, stringing references together until you arrive at the element you need.

Notice also that there are no spaces in object specifiers, except when referring to item names, in quotation marks.

Now that we have a layer object, we’ll identify an attribute or method we want to use. For instance:

this_comp.layer("Solid 1").opacity

Again, a period separates the object and its attribute.

If you ever have trouble with this syntax, you can always let the pick whip help you. Simply put the text cursor at the spot in your expression where you need the object reference, and then drag the pick whip to the object or attribute you need. After Effects will automatically insert the correct object reference. You can drag the pick whip to other windows, including even the Project window.

In addition to the properties we listed earlier, layer objects contain the following attributes or methods:

Layer Attribute or Method Returns object of type Dimension Units
width Number 1 pixels
height Number 1 pixels
start_time Number 1 seconds
in_point Number 1 seconds
out_point Number 1 seconds
has_video Boolean 1 Boolean
has_audio Boolean 1 Boolean
active Boolean 1 Boolean
audio_active Boolean 1 Boolean
audio_levels Property 2 [left, right] decibels
index Number 1 Number
parent Layer, Light or Camera    
source Comp or Footage    
mask(index or name) Mask    
effect(index or name) Effect    

This list is not exhaustive–look in the tables I’ve provided here or in the After Effects User Guide for more information. The list is included here only to show that layer attributes can return a wide variety of objects, including even other comps. You could easily have an object reference that looked like:

this_comp.layer("Nested Comp").source.layer("Solid 1").position

Entire contents © 2001 JJ Gifford.