|
|
Example: Use the expression language reference to write an expression
Follow
along with this example to learn how to use the After Effects expression language
reference to write expressions. The expression created in this example links
the Position property of Solid 2 to the Position property of Solid
1, with the movement of Solid 2 offset by 2 seconds from the movement
of Solid 1.
Create two solid layers: Solid 1 and Solid 2.
Animate the Position property values for Solid 1 using keyframes.
(See About animation, keyframes, and expressions.)
Select the Position property for Solid 2 and choose Animation >
Add Expression or Alt-click (Windows) or Option-click the stopwatch button
for the property. The following expression appears by default:
transform.position
Type the following directly over transform.position:
thisComp
The element thisComp is a global attribute
whose value is a Comp object representing the current composition.
To determine what can follow thisComp in your expression,
look up the return value for thisComp under Global objects, attributes, and methods (expression reference).
Note that thisComp returns
a Comp object. Next, look at Comp attributes and methods (expression reference) to see which attributes and methods
you can use with a Comp object. One option is layer(index).
The index, or number, inside the parentheses specifies the layer
that you want to use. For this example, we assume that Solid 1 is
the first layer in your composition. To retrieve values from the
first layer in the active composition, type .layer(1) at
the end of the expression, to get the following:
thisComp.layer(1)
Again, look at the expression elements reference to see that layer(index) returns
a Layer object. Look at Layer General attributes and methods (expression reference), and find the element you
want to use. For example, if you want to get the values of the Position
property for the layer, type .position at the end
of the expression to get the following:
thisComp.layer(1).position
From Layer General attributes and methods (expression reference), you can see that the position attribute
returns a property. Look up Property attributes and methods (expression reference) and notice that you can add a time
factor to the expression. To add a specific time, such as current
time plus 2 seconds, type .valueAtTime(time+2)at
the end of the expression to get the following:
thisComp.layer(1).position.valueAtTime(time+2)
From Property attributes and methods (expression reference), notice that the valueAtTime method
returns a Number or Array. When an expression returns a Number, Array,
or Boolean (true or false), you cannot add further attributes or
methods to the expression (if you want, however, you can add arithmetic
operators, such as +, -, *,
and /).
|