Type Function
Library system.*
Return value EventDispatcher
Revision Release 2024.3703
Keywords newEventDispatcher, event


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().




-- 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!" )
eventDispatcher:addEventListener( "custom", onCustomEvent ) 

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