Chapter 11. Triggers

A trigger is a block of code that is attached to a variable and executed whenever the value of the variable changes, including the assignment of the initial value. You can also optionally get hold of the old values that were replaced within the trigger. Triggers are very powerful and unique in JavaFX Script, just like bind. Triggers can be attached to normal variables as well as to sequences. First let us see how triggers work for simple variables and then proceed to complicated triggers and sequence triggers.

Defining a Simple Trigger

Here is the typical syntax of a trigger defined on a variable:

Syntax

var <var name>[:data type] [= <initial value>] on replace [old value] {
           // block of code to be executed on value change
       }

or ...

Get Beginning JavaFX™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.