Question: If I’m using a “Runtime:dispatchEvent” to pass a message, how can I arrange such the listenering that picks up the message would have access to my class instance?
That is, in the code below, if I want my File 2 to pickup the event dispatched, but then in the listener code I want this code to have access to the MyWidget instance (i.e. the “new_inst” variable in the code) how would I do this?
The code below doesn’t work…That is want the “new_inst:zoom(event” function to be called, and then after the listner function is then called, that it can access “self.myVariable”.
File 1 (say a scene)
local event = { name="zoom", value = newZ, phase = event.phase} Runtime:dispatchEvent(event)
File 2 (in a class used within the scene somewhere - pseudocode)
MyWidget = {} function MyWidget:new() local new\_inst = {} -- the new instance\\ new\_inst.myVariable = 123 new\_inst.moveableView = display.newGroup() -- \*\*\* DOES NOT GET CALLED \*\*\* function new\_inst:zoom(event) local moveableView = event.target -- \*\* TRYING TO GET ACCESS TO INSTANCE \*\* print("Instance's variable", self.myVariable) return true end new\_inst.moveableView:addEventListener( "zoom", new\_inst ) return new\_inst end return MyWidget