Hi guys,
I am trying to include a ‘touch’ listener for a newTextField(). Main reason is to detect movement (e.g. user is scrolling, and does not actually want to trigger the newTextField). I am using Graphics 2.0 (build 2013.2114 )
I have read these previous items :
http://coronalabs.com/blog/2011/09/24/tutorial-how-to-drag-objects/
The problem is when I add a ‘touch’ listener to the newTextField, it never gets triggered. I have tested it on Mac Simulator and Apple iOS Simulator, and this ‘touch’ listener does not respond at all. A ‘userInput’ listener works fine.
Sample Code :
local field1 = native.newTextField( 50, 100, 100, 35 ) field1.align = "center" field1.size = 32 field1.text = "Hello, world!" field1:setTextColor( 255, 128, 0 ) -- touch listener function function touchListener ( event ) print( "Touch phase : " , event.phase ) if event.phase == "began" then self.markX = self.x -- store x location of object self.markY = self.y -- store y location of object elseif event.phase == "moved" then local x = (event.x - event.xStart) + self.markX local y = (event.y - event.yStart) + self.markY self.x, self.y = x, y -- move object based on calculations above end return true end -- make 'myObject' listen for touch events field1:addEventListener( "touch", touchListener )
Please advise if I am missing something.
Thanks