Question on user moving objects that are created using classes

Hi everyone,

I’ve got a class.newArc function in an arc.lua file that generates arcs when a user clicks on a button that is created in the main.lua file. This works fine so far.

Now after the arc is created, I want to let the user move it around in the screen using touch, and it will stay at the spot the user’s finger is lifted off the screen( i.e. when mouse left click button is released). This is when I’m having trouble, I’ve read the section on table listeners in this guide https://docs.coronalabs.com/guide/events/detectEvents/index.html#function-and-table-listeners but don’t really understand it, nor the example.

would the code be something like this in the main.lua?

local NewArc = require("classes.arc").newArc local widget = require( "widget" ) --event to handle arc creation when user clicks on button, this is working so far local function handleCreateArcButton (event) local MinRadTxt = display.newText("Arc requires a minimum radius of 20", 900, 150, "Arial", 18) ; MinRadTxt.isVisible = false local MaxRadTxt = display.newText("Your input exceeds the maximum radius", 900, 150, "Arial", 18) ; MaxRadTxt.isVisible = false if event.phase == "began" and displayStr \>= '20' then arc = newArc( displayStr, 30, 150, 10, 5) elseif event.phase == "began" and displayStr \< '20' then MinRadTxt.isVisible = true elseif event.phase == "began" and displayStr \>= display.contentWidth then MaxRadTxt.isVisible = true end if event.phase == "ended" then MinRadTxt.isVisible = false ; MaxRadTxt.isVisible = false end end --touch event that allows the user to move the created arc anywhere within the screen, testing unsuccessful, ask forums function NewArc:touch(self, event) if event.phase == "began" and event.x == self.x and event.y == self.y then self.x = event.x; self.y = event.y end end local createArcButton = widget.newButton( {x = 900, y = 50, id = "CreateArc", label = "Generate Arc", onEvent = handleCreateArcButton} ) local myArc = classes.arc:newArc() Runtime:addEventListener("touch", myArc)

I ran it but it gave me the error "attempt to reference NewArc, a local function value, which is this line: function NewArc:touch(self, event)

any ideas?

Got an update, based on this post: https://forums.coronalabs.com/topic/25270-gettersetters-and-listeners-using-classes/ which I just managed to find and some bug fixing on my end, I managed to get it working! Phew…but am open to other possible solutions. 

Thanks cyberparkstudios by the way

Got an update, based on this post: https://forums.coronalabs.com/topic/25270-gettersetters-and-listeners-using-classes/ which I just managed to find and some bug fixing on my end, I managed to get it working! Phew…but am open to other possible solutions. 

Thanks cyberparkstudios by the way