Custom events on custom classes

I’ve created a few classes using the method described on the blog here http://blog.anscamobile.com/2011/09/tutorial-modular-classes-in-corona/.

What I want to do is have one class raise an event and catch the event in another class. Is this possible? I’ve used Runtime:dispatchEvent( {name=“myEvent”} ) however this is a global event and not tied to one instance of a class so doesn’t accomplish what I’m after.

Cheers
Chris [import]uid: 36548 topic_id: 18572 reply_id: 318572[/import]

Chris,

Have you found an answer? I am trying to do the same thing, and so far what I have read about events and dispatchEvent does not make sense to me.

For example, the below code is how I understand you should dispatch events between objects, but in this way the one that is dispatching the event (last line) must know the object it dispatches to, which makes it pointless.

I also prefer to avoid contaminating global space.

[lua]-- main.lua

display.setStatusBar(display.HiddenStatusBar)
print “\n\n\n\n\n\n\n------------------”

local Smurf = {}
Smurf.new = function()
local self = display.newRect( 0,0,100,100 )
self:addEventListener( “tickle”, self )

function self:tickle(e) print “I was tickled” end

return self
end

smurf = Smurf.new()
smurf:dispatchEvent( {name=“tickle”} )
– smurf:dispatchEvent( {name=“tickle”, target=smurf} ) – this is the full syntax, not sure why we have this target here[/lua]
Edit:
Also there is this piece of code that I intend to try, maybe it will be of help
http://developer.anscamobile.com/code/easy-event-handling-your-classes-tables [import]uid: 145050 topic_id: 18572 reply_id: 109172[/import]