I'm using the little class.lua found here to make a solar system with planets. All the bodies in the solar system are of the Body class, and I make an array of bodies to hold all the bodies in the system. Each body has an id, and as long as I'm using the bodies as themselves, I can get the id and do something with it, like treating the Sun as a special case.
Each body is represented visually by Corona display.newCircle(), and I add an event listener for "touch" events to each of those. Then when I'm in the onTouch function, I can get the parent of the circle like this:
local function onTouch( event ) local t = event.target local phase = event.phase if "began" == phase then local parent = t.parent
Looking at the table id's I've verified that the parent of the target is indeed the table of the Body object. What I want to do is get parent.id, so I can know which body I'm dealing with, but the "id" attribute only exists for Body objects. So the question is, how can I cast event.target.parent as a Body object so I can access its attributes and methods?
** Nevermind, the parent of a newCircle is display, so it wouldn't work the way I wanted it to anyway.