Intro to Data Types
In the previous article you learnt that each property expects a value that is of a specific structure, or type. In this article you'll learn what those basics types are and what different properties expect.
In the same way, in After Effects the value of each property has a specific type, and your expression needs to return that same type in order to run without errors.
You can see what type a value is by writing
typeof value in an expression (such as the 'Source Text' property of a text layer).
One of the most common types you will use is
Number, such as
Numbers allow you to do mathematical operations such as add, subtract, divide and multiply them together, in the same way you're used to on a calculator.
60 + 20 / 2;
Properties that expect numbers include:
- Slider Controls
- Separated positions (e.g. X Position, Y Position)
Strings are pieces of text such as
"Jane Doe" or
Strings must be wrapped in single (
'') or double (
You can create a
String with numbers in it, that isn't of a number type, by wrapping it in quotes, e.g.
Properties that expect strings:
- Source Text
You can think of Booleans like switches, as they can either have the value
false (notice these are not wrapped in quotes).
You'll notice that some properties expect more than one value, such as Position or Scale. You can think of these properties as expecting a list of values that's a specific length.
The number of values a property has is called the dimension of the property.
- Scale has 2 values (the X and Y scale) and is a 2 dimensional property
- The position of a 3D layer expects 3 values (the XYZ coordinates) and is a 3 dimensional property
- A color control expects 4 values (the red, green, blue and alpha values) and is a 4 dimensional property
Properties such as Position that have more than one value expect an Array.
You create arrays by enclosing a list of comma seperated values in brackets, for example:
["Item 1", "Item 2", "Item 3"];
Which is a 3 dimensional
Array (as it contains 3 items) of 3
To set the value of a 2D position property (which has 2 dimensions), you would create an Array of 2 number values.
Properties that expect arrays include:
- Position (with un-seperated dimensions)
- Anchor Position
- Color Controls
Strictly speaking, Arrays aren't a data type, but we've included them here for simplicities sake. There's also more data types than in this article that we'll explore later in the series.
You'll notice that while a Source Text property displays text, and expects a string, placing a Number or Array in the expression still works.
For example, giving a 1 dimensional Array instead of a number on an Opacity property:
You can convert a value from one data type to another yourself by using the name of the type followed by parenthesis. For example
Often it's best to do this type conversion yourself rather than relying on coercion.