system.newEventDispatcher()

Type Function
Library system.*
Return value EventDispatcher
Revision Current Public Release (2017.3135)
Keywords newEventDispatcher, event

Overview

Returns a new EventDispatcher that allows you to set up your own private event communications. Like the Runtime and DisplayObject types, this allows users of this EventDispatcher to add listeners to it and receive custom events dispatched via the object:dispatchEvent() function.

This API is intended for plugin developers who want to add their own custom functions similar to Runtime:addEventListener() and Runtime:removeEventListener().

Syntax

system.newEventDispatcher()

Example

-- Create a private event dispatcher
local eventDispatcher = system.newEventDispatcher()

-- Add a listener to the above private event dispatcher
-- Listens for an event named "custom"
local function onCustomEvent( event )
    print( "Received custom event!" )
end
eventDispatcher:addEventListener( "custom", onCustomEvent ) 

-- Dipatch an event named "custom"
-- Only listeners added to this dispatcher can receive it
eventDispatcher:dispatchEvent( { name="custom" } )