> ## Documentation Index
> Fetch the complete documentation index at: https://rive.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ListenerAction

An action performed when an associated [State Machine Listener](/editor/state-machine/listeners) is triggered.

For more information, see [Listener Action Scripts](/scripting/protocols/listener-action-scripts).

## Methods

### `init`

<div class="signature">
  ```lua theme={null}
  init(self: T, context: Context) -> boolean
  ```
</div>

Called once when the listener is created or attached.

```lua highlight={4,5,6,12} theme={null}
type MyListenerAction = {}

-- Called once when the script initializes.
function init(self: MyListenerAction, context: Context): boolean
  return true
end

function perform(self: MyListenerAction, pointerEvent: PointerEvent) end

return function(): ListenerAction<MyListenerAction>
  return {
    init = init,
    perform = perform,
  }
end
```

### `perform`

<div class="signature">
  ```lua theme={null}
  perform(self: T, pointerEvent: PointerEvent) -> ()
  ```
</div>

Called when the associated [State Machine Listener](/editor/state-machine/listeners) is triggered.
This method includes a [PointerEvent](/scripting/api-reference/artboards/pointer-event) parameter containing details about the triggering interaction.

**Deprecated.** Prefer `performAction` with [ListenerContext](/scripting/api-reference/artboards/listener-context); this overload may be removed.

```lua highlight={9,10,11,17} theme={null}
type MyListenerAction = {}

function init(self: MyListenerAction, context: Context): boolean
  return true
end

-- Add your transition logic here.
function perform(self: MyListenerAction, pointerEvent: PointerEvent)
  -- perform action here
end

-- Return a factory function that Rive uses to build the Listener Action instance.
return function(): ListenerAction<MyListenerAction>
  return {
    init = init,
    perform = perform,
  }
end
```

### `performAction`

<div class="signature">
  ```lua theme={null}
  performAction(self: T, listenerContext: ListenerContext) -> ()
  ```
</div>

Called when the associated [State Machine Listener](/editor/state-machine/listeners) is triggered.
This method includes a [ListenerContext](/scripting/api-reference/artboards/listener-context) parameter containing details about the triggering interaction.

```lua highlight={9,10,11,17} theme={null}
type MyListenerAction = {}

function init(self: MyListenerAction, context: Context): boolean
  return true
end

-- Add your transition logic here.
-- `evaluate` is fired every frame while the transition is active.
-- Returning false prevents a transition, true allows a transition.
function performAction(self: MyListenerAction, listenerContext: ListenerContext)
  return true
end

-- Return a factory function that Rive uses to build the Listener Action instance.
return function(): ListenerAction<MyListenerAction>
  return {
    init = init,
    performAction = performAction,
  }
end
```
