Hello guys, Before some days i had seen this bug in my project and i couldnt find out what is this… To check this out i wrote a simple corona app…
I just created a scrollview widget and within it i inserted a button widget… When i touch the button it must change the storyboard scene… in THAT point the corona simulator shows me that:
Runtime error
?:0: attempt to compare number with nil
stack traceback:
[C]: ?
?: in function '\_isWithinBounds'
?: in function <?:135>
?: in function 'dispatchEvent'
?: in function <?:247>
?: in function <?:218>
You pressed and released a button!
this is the code…->
----------------------------------------------------------------------------------
--
-- scenetemplate.lua
--
----------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local widget = require "widget"
local scene = storyboard.newScene()
if (display.pixelWidth \> 320) then
display.setStatusBar(display.DefaultStatusBar)
else
display.setStatusBar(display.HiddenStatusBar)
end
----------------------------------------------------------------------------------
--
-- NOTE:
--
-- Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
bg = display.newImageRect("coffeeBg.png",320,480)
bg.x = display.contentWidth/2
bg.y = display.contentHeight/2
group:insert(bg);
local scrollView = widget.newScrollView{
top = 5,
width = 320,
height = 430,
scrollWidth = 320,
scrollHeight = 430,
hideBackground=true,
verticalScrollDisabled = true,
horizontalScrollDisabled= false,
maskFile="mask1.png"
}
local function handleButton\_hotel( event )
local phase = event.phase
if "ended" == phase then
print( "You pressed and released a button!" );
storyboard.gotoScene("scenetemplate1");
end
end
local hotel = widget.newButton
{
left = 10,
top = 195,
width = 136,
height = 208,
defaultFile = "hotel.jpg",
overFile = "hotel\_.jpg",
id = "button\_1",
onEvent = handleButton\_hotel
}
scrollView:insert(hotel);
group:insert(scrollView);
-----------------------------------------------------------------------------
-- CREATE display objects and add them to 'group' here.
-- Example use-case: Restore 'group' from previously saved state.
-----------------------------------------------------------------------------
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
-----------------------------------------------------------------------------
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
storyboard.removeScene( "scenetemplate" )
-----------------------------------------------------------------------------
-- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
-----------------------------------------------------------------------------
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
-----------------------------------------------------------------------------
-- INSERT code here (e.g. remove listeners, widgets, save state, etc.)
-----------------------------------------------------------------------------
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: 185094 topic_id: 36654 reply_id: 336654[/import]