If you’re using Data Binding, you can listen for triggers or value changes without needing Events.
LoadComplete
fired when transitioning from a complete
timeline animation state to an idle
state. You can subscribe to Rive events with a callback that the runtime may invoke, and from there, your callback can handle extra functionality at just the right moment when the event fired.
Other practical use cases for events:
- Coordinating audio playback at specific moments in an animation, see Audio Events
- Opening a URL when specific interactions have occurred
- Adding haptic feedback on meaningful touch interactions
- Implementing functionality on Buttons and other UI elements
- Send semantic information
- Communicate any information your runtime needs at the right moment
Subscribing to Events
When you subscribe to Rive events at runtime, you subscribe to all Rive events that may be emitted from a state machine, and you can parse through each event by name or type to execute conditional logic. Let’s use a 5-star rater Rive example to set any text supplied with events and open a URL if one is given.Examples
- Star rating example
- Neostream example (Chrome only) (This example does not make use of the new Audio Events feature)
High-level API usage
Adding an Event Listener
Similar to theaddEventListener()
/ removeEventListener()
API for DOM elements, you’ll use the Rive instance’s on()
/ off()
API to subscribe to Rive events. Simply supply the RiveEvent enum and a callback for the runtime to call at the appropriate moment any Rive event gets detected.Example Usage
Low-level API usage
When using the low-level APIs (i.e.@rive-app/canvas-advanced
), you’ll need to catch Rive events reported during the render loop yourself via your created state machine instance (see docs on Low-level API Usage). To achieve this, before advancing the state machine:- Determine the number of Rive events reported since the last frame via the state machine’s
reportedEventCount()
API - Iterate over the events and grab a reference to an Event via the state machine’s
reportedEventAt(idx)
API