Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Passing touch events from interior class to external class — Gideros Forum

Passing touch events from interior class to external class

BlueByLiquidBlueByLiquid Member
edited March 2013 in General questions
I have a class X that contains a Class Y. Class Y listens for touch events and I want to listen to some of those events. The issue is that I want objects which hold class X to register for those events but they have no knowledge of class Y. I am a bit confused as how to do this. I could certainly create passthrough events but I want to use the gideros event framework. I feel like I am being stupid here. Any help?


  • ScouserScouser Guru
    edited March 2013
    Simply pass self as a parameter when you call ClassY.new from ClassX something like
    function ClassY:init(parent)
    	self.parent = parent		-- This is the parent (calling function)
    	-- add event listeners etc
    function ClassY:touchFunc(event)
    	self.parent:doStuff(event)	-- Call a parent function
    function ClassX:init()
    	local child = ClassY.new(self) -- pass this instance of ClassX to ClassY
    function ClassX:doStuff(event)
    	-- do stuff with the event data
Sign In or Register to comment.