Okay, I realized I needed to change this some to where I add controls right on the scene and image rather than use buttons drawn on the background image. So I commented out the event for the image and added a button. The button worked fine and the page scrolled like I wanted. Then I added an event for the button and when I click on it the color changes to the pressed color and stays like that. I can still scroll but the event that prints the button has been pressed never fired. Below is the code for the entire scene. Am I doing something wrong?
Thanks!!!
----------------------------------------------------------------------------------
--
-- SceneEvents.lua
--
----------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local widget = require "widget"
local imgHeader
local onbtnHomeEvent = function (event )
if event.phase == "release" then
print( "You pressed and released a button!" )
end
end
local function someTouchHandler(self, event)
print ("0") --This does happen
if event.phase == "ended" then
print ("1") --Never happens
-- do what you want for the touch
elseif event.phase == "moved" then -- Check if you moved your finger while touching
print("2") --Never happens
local dx = math.abs( event.x - event.xStart ) -- Get the x-transition of the touch-input
local dy = math.abs( event.y - event.yStart ) -- Get the y-transition of the touch-input
if dx \> 5 or dy \> 5 then
print ("3") --Never happens
scrollView:takeFocus( event ) -- If the x- or y-transition is more than 5 put the focus to your scrollview
end
end
return true
end
-- function to listen to scrollView events
local function scrollViewListener( event )
local s = event.target -- reference to scrollView object
if event.type == "beganScroll" then
print( "beganScroll event type" )
elseif event.type == "endedScroll" then
print( "endedScroll event type" )
elseif event.type == "movingToTopLimit" then
print( "movingToTopLimit event type" )
elseif event.type == "movingToBottomLimit" then
print( "movingToBottomLimit event type" )
elseif event.type == "movingToLeftLimit" then
print( "movingToLeftLimit event type" )
elseif event.type == "movingToRightLimit" then
print( "movingToRightLimit event type" )
end
end
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local scrollView = widget.newScrollView{
width = 320,
height = 424,
top = 0,
left = 0,
scrollWidth = 320,
scrollHeight = 700,
maskFile="mask\_home.png",
listener = scrollViewListener,
}
local screenGroup = self.view
imgHeader = display.newImage( "screen\_main.png" )
scrollView:insert(imgHeader)
--imgHeader.touch = someTouchHandler
--imgHeader:addEventListener("touch", imgHeader) -- [!] added due to flag code
--imgHeader:addEventListener("touch", someTouchHandler)
local btnHome = widget.newButton{
label = "Home",
font = "Arial",
fontSize = 14,
height=28,
width=80,
labelColor = { default={ 0 }, over={ 0 } },
defaultColor = { 206, 231, 231, 255 },
strokeColor = { 206, 231, 231, 255 },
onEvent = onbtnHomeEvent
}
scrollView:insert(btnHome)
btnHome.x = 53
btnHome.y = 90
scrollView:insert(btnHome)
imgBarHome = display.newImage( "bar\_home.png",0,425)
screenGroup:insert(imgBarHome)
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
imgHeader.ready = true -- [!] flag method
--[[[!] disabled due to flag method
-- Update Lua memory text display
local showMem = function()
imgHeader:addEventListener( "touch", imgHeader )
end
local memTimer = timer.performWithDelay( 1000, showMem, 1 )
--]]
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
imgHeader.ready = false -- [!] flag method
--imgHeader:removeEventListener( "touch", imgHeader ) -- [!] disabled due to flag method
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene
[import]uid: 184193 topic_id: 34809 reply_id: 138796[/import]