Accessing elements in an expression
Use the expression language to access properties in After Effects that have a numeric value. To access a value, use a chain of object references, separated by the period (.) operator. To understand the order in which you can add elements to an expression, use the After Effects expression language guide to learn what the element returns. Consider the following procedure as an example of how to construct an expression using the After Effects expression language guide:
To construct a simple expression: - Start with two layers.
- Select the Position property for the first layer in the composition and choose Animation > Add Expression. The following expression appears by default:
position - Type the following directly over the word "position:"
this_comp - The element "this_comp" is a global attribute whose value is a Comp object representing the current composition.
- To determine what can follow "this_comp" in your expression, look up the return value for "this_comp" under Global attributes and methods.
- Note that "this_ comp" returns a Comp. Next, look at the Comp attributes and methods to see what you can use with a Comp. One option is "layer(index)". The index, or number, inside the parentheses specifies the layer that you want to use. To retrieve values from the second layer in the active composition, type the following:
this_comp.layer(2) - Again, look at the expression language guide to determine that "layer(index)" returns a Layer. Look at Layer attributes and methods, and find the element you want to use. For example, if you want to access the Position property values for the layer, type the following:
this_comp.layer(2).position - From Layer attributes and methods, determine that the position attribute returns a Property. Look up Property attributes and methods and notice that you can add a time factor to the expression. To add a specific time, such as current time minus 2 seconds, type the following:
this_comp.layer(2).position.value_at_time(time-2) - From Property attributes and methods, notice that the time factor "value_at_time(time)" returns a Number. When an element returns a Number, Array, or Boolean (such as true or false), you cannot add other attributes or methods to the expression (if you want, however, you can add operators such as +, -, *, or /).
- Click outside of the expression to activate it.
|