Javascript for After Effects
These are standard and common functions used by After Effects. Although many can be used in an Expressions field, all of these are accessable by running a script manually.
Types of scripts
There are two basic types of scripts which AE uses, uncompiled and compiled.
Uncompiled Javascript
An uncompiled Javascriptis the most common script you'll see. These are the scripts have filenames ending in .jsx and can be opened with any text editor and edited, and you can see the javascript code when opened. These scripts are meant to be flexible and available for anyone to edit.
Compiles Javascript
Compiles scripts work exactly like a compiled script only the file is encoded for protection. These types of scripts are meant for commercial distribution and cannot be edited by anyone but the author.
Variables
Variables can be delvaref with a "var" in from of them.
Escape Characters
Code | Char | Output |
---|---|---|
\' | ' | single quote |
\" | " | double quote |
\\ | \ | backslash |
\b | backspace | |
\f | form feed | |
\n | new line | |
\r | carriage return | |
\t | tab |
Operators
Comparison Operators
Operator | Description | Example ( x=3 ) | Result |
---|---|---|---|
== | Is equal to ( never use a single = ) | x==5 | false |
=== | Is absolutely equal to (this checks variable type too)* |
x===3
|
true
|
!= | Is not equal to | x!=4 | true |
!== | is NOT equal to (this checks variable type too)* |
x!==3
|
false
|
> | Is greater than | x>5 | false |
< | Is less than | x<5 | true |
>= | Is greater than or equal to | x>=5 | false |
<= | Is less than or equal to | x<=5 | true |
Logical Operators
Operator | Description | Example ( x=3 ) | Result |
---|---|---|---|
&& |
and | ( x>1 )&&( x-1>1 ) | true |
|| | or | ( x==3 ) || ( x="three" ) | true |
! | is not | !(x==3) | false |
Arithmetic Operators
Operator | Description | Example ( x=3 ) | Result |
---|---|---|---|
+ | Add | x = x+2 | x = 5 |
- | Subtract | x = x-2 | x = 1 |
* | Multiply | x = x*2 | x = 6 |
/ | Divide | x = x / 2 | x = 1.5 |
++ | Increment by
Increment then return Return then increment |
x ++ 2
++ x x ++ |
x = 5
x = 4 x = 3 (next time it will = 4) |
-- | Decrement by
Decrement then return Return then decrement |
x -- 2
-- x x -- |
x = 1
x = 2 x = 3 (next time it will = 2) |
% | Divide and get remainder (Modulus) | x % 2 | x = 1 |
Assignment Operators
Operator | Description | Example ( x=3 ) | Result |
---|---|---|---|
= | Assigns a value | x = 5 | x = 5 |
+= | adds a value | x += 5 | x = 8 |
-= | subtracts a value | x -= 5 | x = -2 |
*= | multiplies a value | x *= 5 | x = 15 |
/= | Divides by a value | x /= 5 | x = 0.6 |
%= | Divides and gets remainder of a value (Modulus) | x %= 5 | x = 3 |
Event Handler
The following are NOT supported by AE at this time.
- onAbort
- onBlur
- onChange
- onClick
- onDblClick
- onDragDrop
- onError
- onFocus
- onKeyDown
- onKeyPress
- onKeyUp
- onload
- onMouseDown
- onMouseMove
- onMouseOut
- onMouseOver
- onMouseUp
- onMove
- onReset
- onResize
- onSelect
- onSubmit
- onUnload
Methods
Dialogs
Name | Secure | Expression | Description |
---|---|---|---|
alert() | yes | no | Brings up on OK dialog, used to send the user a message. |
confirm() | yes | no | Brings up an ok / cancel dialog and returned the value as a boolean.(good for if statements) |
Error() | yes | no | Brings up an error dialog. |
prompt() | yes | no | Brings up an ok / cancel dialog asking for user input. If no input is entered, the dialog returns false. |
Math
Name | Secure | Expression | Description |
---|---|---|---|
isNaN() | yes | yes | Checks if a value is Not a Number. |
Math.sqrt() | yes | yes | Finds the square root of a number. |
String Object
new String(string)
- charAt() Returns an index of a specified character position
- charCodeAt() Returns the UNICODE value of a specified character at position
- concat() Joins two or more strings together into one
- fromCharCode() Converts UNICODE values into characters
- indexOf() Finds the first occurance of a string or character and returns its index value of its location. If the string is not found 0 is returned.
- lastIndexOf() Finds the last occurance of a string or character and returns its index value of its location. If the string is not found 0 is returned.
- match() Searches a string for a substring, then returns any matches
- replace() Searches a string for a substring, then replaces any matches with a new string
- search() Searches a string for a substring, then returns the position of any matches
- slice() Extracts a part of a string and returns a new string
- split() Creates a substring of a specified string
- substr() Extracts the characters from a string, beginning at a specified start position, and through the specified number of character
- substring() Extracts the characters from a string, between two specified indices
- toLowerCase() Converts a string to lowercase letters
- toUpperCase() Converts a string to uppercase letters
- valueOf() Returns the primitive value of a String object
- toString() Converts a value into a string
String Object Properties
- .Constructor - a reference to the function which created the object
- .Length - returns the number of characters in a string
- .Prototype - Allows you to add methods and properties to the sring object
Objects and Properties
An Object can be a File, project, folder, comp, layer, effect, etc. Each Object has a set of Properties; a file has a name, a layer has potition and rotation. Below are Objects and a few of their possible properties. In After Effects a specific object hierarchy is used. Meaning that objects contain sub-objects as well as properties.
- application - app
- settings
- project
- renderQueue
- renderQueueitem(s)
- outputModule(s)
- renderQueueitem(s)
- compItem
- layer(s)
- properties
- proxySource
- solidSource
- color
- placeholderSource
- fileSource
- file
- solidSource
- layer(s)
- footageItem
- mainSource
- solidSource
- color
- placeholderSource
- fileSource
- file
- solidSource
- proxySource
- solidSource
- color
- placeholderSource
- fileSource
- file
- solidSource
- mainSource
- folderItem
- item(s)
- renderQueue
- system
- file
- folder
- socket
Classic Java Objects
- Anchor
- Applet
- Area
- Array
- Boolean
- Button
- Checkbox
- Date
- Document
- Event
- FileUpload
- Form
- Frame
- Function
- Hidden
- History
- Image
- Layer
- Math
- Object
- Reset
- Screen
- String
- Submit
- Text
- Textarea
- Window
- Link
- Location
- Navigator
- Number
- Option
- Password
- Radio
- RegExp
- Select
Special
- + Used between to strings to quickly concatinate them together ( instead of using the concat() method ) (you can also add with +=)
- ,
- ?:
- delete
- new
- this is a context dependand object or property. It's connected to whatever is being passed to a function.
- typeof
- void
Statements
- try is like an if statement for errors. Everything in a try block will be executed and but if errors occur, catch statements can pick up the error and parse it.
- throw will send an error out for a catch statement.
- catch looks for try or thrown errors and reports them.
- if checks a true / false condition and executed if true.
- else
- do
- while
- for
- for-in
- continue
- break
- switch looks up a value like an "if" statement would, but handles multiple results. This is like using s series of elseIf statements.
- export
- import
- label
- return
- var
- with
Constants
- Main Index
- Infinity
- NaN
- undefined
- null
Commenting
- // - Single line comment
- /* */ - Book ends for a multi-line comment