Brent and Belunch the code works fine with default file or not. But if you use the same code in storyboard, then the button’s don’t work.
Here is the code in storyboard:
[lua] local storyboard = require( “storyboard” )
local widget = require( “widget” )
local scene = storyboard.newScene()
local W = display.contentWidth
local H = display.contentHeight
local scrollView, button1, button2
– The touch listener function for the button (created below)
local function handleButtonEvent( event )
local phase = event.phase
local t = event.target
if ( phase == “began” ) then
scrollView.hasFocusFlag = false
elseif ( phase == “moved” ) then
local dy = math.abs( ( event.y - event.yStart ) )
– If the touch on the button has moved more than 10 pixels,
– pass focus back to the scroll view so it can continue scrolling
if ( dy > 10 ) then
scrollView:takeFocus( event )
scrollView.hasFocusFlag = true
t:dispatchEvent( { name=“touch”, target=t, phase=“ended” } )
end
elseif ( phase == “ended” ) then
if ( scrollView.hasFocusFlag == false ) then
print( event.target.id…" RELEASED!" )
end
end
return true
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– Create the ScrollView
scrollView = widget.newScrollView
{
top = 100,
left = 10,
width = 300,
height = 400,
scrollWidth = 600,
scrollHeight = 800,
hideBackground = true,
horizontalScrollDisabled = true
}
scrollView.hasFocusFlag = false
button1 = widget.newButton{ defaultFile = “menuBtn.png”, overFile = “menuBtnOver.png”, width = 80, height = 80, id = “button1”, label = “BUTTON 1”, onEvent = handleButtonEvent}
button2 = widget.newButton{ defaultFile = “menuBtn.png”, overFile = “menuBtnOver.png”, width = 80, height = 80, id = “button2”, label = “BUTTON 2”, onEvent = handleButtonEvent}
button1.x = W * 0.5; button1.y = H * 0.3;
button2.x = W * 0.5; button2.y = H * 0.3 + button2.height * 1.1;
scrollView:insert( button1 )
scrollView:insert( button2 )
group:insert(scrollView)
end
– Called BEFORE scene has moved onscreen:
function scene:willEnterScene( event )
local group = self.view
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
end
– Called AFTER scene has finished moving offscreen:
function scene:didExitScene( event )
local group = self.view
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
end
– Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan( event )
local group = self.view
local overlay_name = event.sceneName – name of the overlay scene
end
– Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded( event )
local group = self.view
local overlay_name = event.sceneName – name of the overlay scene
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “willEnterScene” event is dispatched before scene transition begins
scene:addEventListener( “willEnterScene”, 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 )
– “didExitScene” event is dispatched after scene has finished transitioning out
scene:addEventListener( “didExitScene”, 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 )
– “overlayBegan” event is dispatched when an overlay scene is shown
scene:addEventListener( “overlayBegan”, scene )
– “overlayEnded” event is dispatched when an overlay scene is hidden/removed
scene:addEventListener( “overlayEnded”, scene )
return scene [/lua]