Part of the mystery of expressions is the vocabulary of the technical language. What exactly is an array? What’s the difference between a method, an argument, or a statement? What do all of these things do? I admit that those were a bit intimidating when I first started learning about expressions and coding myself, so I thought that I’d put together a handy list of expression definitions to help de-mystify things a bit more.
Methods and Returns
A method is a command that makes an expression do a certain thing. More technically, methods tell After Effects to run a series of predefined mathematical computations on an argument in order to produce a return, which is a value or series of values that After Effects then uses to drive an animation. Don’t worry if you don’t know what an argument is; we’ll discuss them in a second. Methods are easy to spot, they are always followed by an open/close parenthesis pair, like so:
lookAt(), wiggle(), layer(), effect()
Some methods can be used in multiple places, like the wiggle() method. Others need to be applied to only specific properties in order to work. For example, the lookAt() method can only be applied to a layer’s orientation property in order to work correctly. Likewise, returns can be nested within other methods or mathematical operations in order to produce even more complex results.
Arguments, Types of Values, and Operators
As I stated a moment ago, methods require arguments in order to return a value. An argument is a value that is used by a method to produce a return (see above if you need those terms redefined). Some arguments can be very simple, requiring only a single number, or can be very complex, requiring a 5-dimension array. With complex arguments, syntax (or the method of arrangement of those values) becomes critical.
There are four types of values that can be used in arguments, and returned by methods:
Strings – Strings are text. When the user needs to input a string, the user does so by writing the string within single or double quotes. When After Effects produces the string the quotation marks are not present. Sometimes the string will be used to refer to a certain layer, layer attribute, or effect parameter. Other times, strings will be used to produce text on the screen.
Be aware! Strings need to be written precisely – even a misplaced capital or lower case letter, as well as a misspelled word, can cause a fault in the expression.
Numbers a number is considered to be a single numerical value. That’s it, nothing fancy.
Arrays Arrays are the most complex values that can be provided or returned. Arrays a series of two or more numbers, strings, or other arrays within brackets, like so:
[value1, value2, value3]
Each value is called a “dimension,” and theoretically there is no upper limit on the amount of dimensions that an array can contain. Practically speaking, however, there are no arrays that are larger than 6 dimensions use in After Effects.
An example of a 2D array are position values in 2 dimensions, while examples of 3D arrays would be position values in 3-dimensions, RGB color values, orientation values, 3D anchor points, etc. The number of dimensions in an array is determined either by the property that you are trying to reference, or by the syntax required by a method. You’ll need to consult the Expression Language Reference section of the After Effects Reference Manual for more information about specific method syntax requirements
Boolean – True or False values. Usually, you will need to write out the word specifically.
Lastly, operators are symbols that tell After Effects to run mathematical operations on numbers or numerical values within arrays. By definition, operators cannot work on strings or booleans, since they are text. Examples of operators are +,-,*,/, etc.
Attributes, Parameters, and Statements
Attributes are the properties of a layer or footage item, whose value(s) can be accessed, operated upon, and returned by an expression. For example, the transform property group contains the following attributes: anchor point, position, rotation, scale, and opacity. You can access them by declaring the layer and typing, for example, “.transform.opacity” if you want to access the opacity attribute’s value, or “.transform.rotation” if you want to access a layer’s rotation attribute value. A full example would look like so:
Parameters, on the other hand, are the properties of an effect. Effects, of course, are non-standardized so there is no practical way to include all of them in the expression language of After Effects. Additionally, new effects are generated very frequently, so keeping up with the sheer number of them is nearly impossible. Instead, in order to allow designers to access the values generated by an effect, Adobe has created the “.param()” command. Suppose that you want to link the opacity of one layer with the brightness of a lens flare applied to a different layer. In that case, you would place the following expression onto the first layer’s opacity property:
thisComp.layer(“Lens Flare Layer Name”).effect(“Lens Flare”).param(“Flare Brightness”);
However, Adobe has also included a shortcut to limit the amount of code writing that designers need to do. Instead of typing “.param()”, you can instead simply write the desired parameter after calling the effect. So using this shortcut, the previous example would look like this:
thisComp.layer(“Lens Flare Layer Name”).effect(“Lens Flare”)(“Flare Brightness”);
All of the code that I wrote above are examples of statements. Statements are executable lines of code, ending with a semicolon. Often, statements simply access attributes or parameters and return that value to the property containing the expression. Some statements assign variables, however, while other statements use methods and operators to calculate values, or even set conditional statements.
Now that you know the definition of these terms, I hope that your expression research and work becomes a little bit easier!