Expression Basics
Native Methods
In the article on native attributes you learnt how to find and access the attributes built into the After Effects composition, layer and property objects.
As well as attributes, these object have properties which are functions.
These built in functions are known as native methods.
Finding and using native methods
The same principles learned in the articles on functions and native attributes apply to native methods.
For an in depth look at how to reference the built in objects, and how functions work, see the previous articles in this series.
You can spot the native methods in the expression language menu as they contain parenthesis (()
) after their name, as they are a functions, while native attributes do not have parenthesis.
Some methods also have equals signs in the function parameters, which show the default value of that parameter.
In the sourceRectAtTime()
method pictured above, the default value for the first parameter is time
, and the second parameter defaults to false
.
Commonly used methods
Below is a list of native methods most commonly used in expressions, grouped by their parent object. Knowing when and how to use these methods is a key part of writing expressions.
For a more detailed explanation for each of these methods, see the Expression language reference by Adobe.
Composition
Methods on composition objects, such as thisComp
or comp("Lower Third
, include:
layer(index || name)
: Returns the relevant layer objectmarker.key(index || name)
: Returns the relevant marker object
Layer
Methods on layer objects, such as thisLayer
or thisComp.layer("Name")
, include:
add(vectorA, vectorB)
: Adds two vector arraysmul(vector, amount)
: Multiplies every dimension of a vector by the amountclamp(value, limitA, limitB)
: Constrains a value between the provided limitsrandom()
: Returns a random number between zero and one
Property
Methods on property objects, such as thisProperty
or thisLayer.transform.opacity
, include:
valueAtTime(time)
: Returns the value of the property at the input timesmooth()
: Applies a box filter to smooth the value of the property over timenearestKey(time)
: Returns the key object nearest in time to the input
Wrapping up
Native methods are one of main building blocks of expressions, allowing you to perform complex tasks with minimal code.
Knowing how functions and native attributes work gives you further insight into how best to use native methods in your own expressions.