Skip to main content
Scripting allows you to read, modify, and subscribe to changes in View Model properties, as well as create new View Model instances at runtime.
For a conceptual overview of View Models and how they drive your graphic, see View Models & Data Binding.

View Models

There are three ways that a script can gain access to a View Model and its properties:

Context

The init lifecycle function includes a context parameter that gives you access to your view models. This allows you to read values (strings, enums, lists, etc.), set values, fire triggers, listen for triggers, and subscribe to value changes.
In addition to view models, Context gives you access to named assets and update scheduling.

View Models as Inputs

You can create a Script Input that can be bound to a view model. This allows you to read values (strings, enums, lists, etc.), set values, fire triggers, listen for triggers, and subscribe to value changes.
For a detailed explanation, see View Models Inputs.

Binding Inputs

If you only need to read, not set view model properties, you can data bind view model property values to script inputs. For more information see Data Binding Inputs.

Nested View Models

To reference a nested view model, use getViewModel.

Reading and Setting Properties

The following methods allow you to reference view model properties:

Listening for Property Changes

Add a Listener

Use addListener to listen for triggers or changes to view model properties.

Remove a Listener

Always remove listeners when they are no longer needed to avoid memory leaks.

Creating a View Model Instance

Coming soon