Fundamentals

This section of the composition scripting documentation includes essential cheat sheets for the following:

Composition scripting fundamentals

The initialization of composition scripts works from the bottom up and starts from the lowest child up to the root.

All composition scripts have an init() and a close() function. Initialize your custom code and variables in the init() function and use the close() function to clean up memory and clear timeouts and intervals.

The global script

Global Script
(function() {

  return {

    init: function(context) {
      // ...
    },

    close: function() {
      // ...
    }
  };
})();

The init function is called after the script is evaluated. The context provides access to common objects, including global storage and utility functions.

The close function is called when the script is unloaded, for example when a browser tab is closed. Use it to clean up memory and clear timeouts, intervals, XHR requests, etc.

Sub-composition scripts

The init function is called after the script is evaluated. The comp argument contains the composition object the script is attached to. The context provides access to common objects, including custom global objects and utility functions.

The close function is called when the script is unloaded, e.g. when closing the browser tab. Use it to clean up memory and clear timeouts, intervals, XHR requests, etc.

Object types, properties, and methods

The composition object

The composition object provides methods to navigate through the composition structure, read and update content, transformation and effects parameters, access the DOM element, and trigger animations.

The most frequently used methods are:

find()

Returns an array of composition objects that matches the defined search string.

findGroup()

Returns an array of group objects that matches the defined search string.

findWidget()

Returns an array of widget objects that matches the defined search string.

getPayload()

Returns the control node content from the composition as an array of key value pairs.

getPayload2()

Returns the control node content from the composition as a JSON object.

getState()

Returns the animation state of the composition.

Animation state
Description

In

Timeline at In state

Out

Timeline at Out state

Out1

Timeline 1 at Out state

Out2

Timeline 2 at Out state

getSubcompositionById()

Returns the composition object defined by its ID.

id

The composition ID.

jumpTo()

Jumps to the specified animation state.

listSubcompositions()

Returns an array of JSON objects containing sub-composition names and IDs.

name

The composition name.

parent()

Returns the parent composition object.

playTo()

Plays the animation to the specified state.

setPayload()

Sets the control node content of the composition.

The widget object

The widget object provides methods to read and update widget specific properties, transformation and effects parameters, and access the Dom element.

The most frequently used methods are:

getDomElement()

Returns the HTML Dom element for the widget.

getPayload()

Returns the widget type specific properties as a JSON object.

getPositionX(), getPositionY()

Returns the positionX or positionY value in a percentage.

getRotationZ()

Returns the rotationZ value in degrees.

getSizeX(), getSizeY()

Returns the sizeX or sizeY value in a percentage.

getVisibility()

Returns the visibility as a boolean.

id

Returns the widget ID.

setPayload()

Sets one or multiple widget specific properties.

setPositionX(), setPositionY()

Sets the positionX or positionY value in a percentage.

setRotateZ()

Sets the rotationZ value in degrees.

setSizeX(), setSizeY()

Sets the sizeX or sizeY value in a percentage.

setVisibility()

Sets the visibility as a boolean.

Context and utility functions

global:{}

A custom global object including variables, objects, and functions.

utils.createDataStream()

Creates a data stream listener.

Create a Data Stream in the Data Stream Manager!

utils.createMoment()

Creates a momentjs object.

For a detailed description of the momentjs library visit https://momentjs.com/.

utils.createTinyColor()

Creates a tinycolor object.

For a detailed description of the tinycolor library visit https://github.com/bgrins/TinyColor

utils.getSingularWindow()

Returns the render window name.

Event listener

comp.addListener(eventType, callbackFunction)

The addListener() method attaches an event handler to the composition without overwriting existing event handlers. You can add multiple event handlers for the same event type.

The first parameter defines the type of the event. Event types include:

The second parameter is a function that you call when an event occurs.

payload_changed

This event occurs when the control nodes of the composition or a sub-composition changes.

The callback function receives three parameters:

  • event: the type of the event

  • msg: a JSON object containing the composition ID, name, and payload

  • e: an event handle

state_changed

This event occurs at the end of an animation when the animation state of the composition or a sub-composition changes.

The callback function receives three parameters:

  • event: the type of the event

  • msg: a JSON object containing the composition ID, name, and new animation state

  • e: an event

timeline_event

This event occurs at the start and end of an animation of the composition or a sub-composition.

The callback function receives three parameters:

  • event: the type of the event

  • msg: a JSON object containing the composition ID, name, and timeline event details

  • e: an event

button_clicked

This event occurs when a button control node is clicked.

The callback function receives three parameters:

  • event: the type of the event

  • msg: a JSON object containing the composition ID, name, and data node details

  • e: an event

datanode_payload_changed

This event occurs when a data node of the composition or a sub-composition changes.

The callback function receives three parameters:

  • event: the type of the event

  • msg: a JSON object containing the composition ID, name, and data node details

  • e: an event

message

This event occurs when the graphics SDK, widgets, and interactive events send custom messages to the comp or a sub comp.

The callback function receives three parameters:

  • event: the type of the event

  • msg: a JSON object containing the composition ID, name, details and payload

  • e: an event

The following logs show the msg object returned by interactive events.

Last updated

Was this helpful?