I’m having problems being able to get into the “moved” phase on touch events in my objects that are a part of a scroll view. In my below code, I have a ball I want to move. I get to the “began” phase just fine, but when I move the mouse while holding the ball the scollview scrolls.
local widget = require ("widget")
local page = widget.newScrollView({
width=320,height=480,
bgColor = {0,0,0},
locked = false,
topPadding = 50,bottomPadding = 50,
leftPadding = 50, rightPadding = 50,
hideScrollBar=true,
})
function dragball(event)
local ball = event.target
if event.phase == "began" then
ball.moving = true
ball.parent:insert(ball)
display.getCurrentStage():setFocus( ball )
ball.x0 = event.x - ball.x
ball.y0 = event.y - ball.y
elseif event.phase == "moved" then
if ball.moving == false then return false end
ball.x = event.x - ball.x0
ball.y = event.y - ball.y0
elseif event.phase == "ended" or event.phase == "cancelled" then
ball.moving = false
display.getCurrentStage():setFocus( nil )
end
end
local rect = display.newRect(10,10,310,470)
page:insert(rect)
local ball = display.newCircle(200,200,20)
ball:setFillColor(0,255,0)
ball:addEventListener('touch',dragball)
page:insert(ball)
Help please… Thanks! [import]uid: 213270 topic_id: 35261 reply_id: 335261[/import]