I had the same exact issue after switching my buttons from the ui.lua paradigm over to the widget button. I was banging my head for half a day before getting this to work by extracting a small bit of the ui.lua code. It works by checking to see if the user has dragged his/her finger outside the button. Try this:
[blockcode]
local widget = require “widget”
local buttonPress = false --this is our marker to determine if the button is being pressed down
local function pushButton(event)
local btn = event.target
local bounds = btn.contentBounds
local x,y = event.x,event.y
local isWithinBounds = bounds.xMin <= x and bounds.xMax >= x and bounds.yMin <= y and bounds.yMax >= y
if event.phase == “press” then
buttonPress = “true”
–do your button-press activities…
elseif event.phase == “moved” then
if not isWithinBounds then
– button is still pushed down, but the touch location has moved
– outside the boundary of the button
buttonPress = “false”
– stop your button-press activities…
– and stop tracking the location of the touch event
display.getCurrentStage():setFocus(nil)
end
elseif event.phase == “release” then
buttonPress = “false”
–stop your button-press activities…
end
end
local button = widget.newButton{
default = “x.png”,
over = “xOver.png”,
onEvent = pushButton,
font = “Denmark”,
fontSize = 24,
label = “Push Button”,
labelColor = { default={ 255, 255, 255, 255 }, over={ 0 } }
}
local function buttonCall()
if buttonPress == “true” then
– activities to continuously take place while button is pressed
– down AND inside the button boundary
end
end
Runtime:addEventListener( “enterFrame”, buttonCall)
[/blockcode]
Note that the “moved” event phase now allows the user to move his/her finger around inside the button, and nothing will change until the finger goes outside the boundary. (in my case, the thrust for a ship’s engines will continue to push until the user either lets go or drags his/her finger outside the button)
Cheers!
Jerry Palmroos
Charlotte [import]uid: 151653 topic_id: 22243 reply_id: 114113[/import]