I have a module that I want to dispatchEvents that I pickup in another module. Seems you need a display object to use addEventListener and dispatchEvent.
Hi @soggybag,
You can also dispatch events to the Runtime object, as follows:
[lua]
local myListener = function( event )
print( "Event: " … event.name )
print( "Custom value: " … event.myCustomValue )
end
Runtime:addEventListener( “myEventType”, myListener )
local function dispatchSomething()
Runtime:dispatchEvent( { name=“myEventType”, myCustomValue=“It works!” } )
end
timer.performWithDelay( 1000, dispatchSomething )
[/lua]
Hope this helps,
Brent
Hi @soggybag,
You can also dispatch events to the Runtime object, as follows:
[lua]
local myListener = function( event )
print( "Event: " … event.name )
print( "Custom value: " … event.myCustomValue )
end
Runtime:addEventListener( “myEventType”, myListener )
local function dispatchSomething()
Runtime:dispatchEvent( { name=“myEventType”, myCustomValue=“It works!” } )
end
timer.performWithDelay( 1000, dispatchSomething )
[/lua]
Hope this helps,
Brent