Hi
I am using a Scroll View to display several images across the screen. When I place the images inside a scroll view, the touch event generates: -
“runtime error: attempt to call a table value”.
So, when I use this: -
for i = 1,26 do local but = display.newImage(options[i].buttonPath) but.id = i but.x = options[i].x but.y = options[i].y but:addEventListener( "touch", OptionClick ) scView:insert(but) end
When I do not use the Scroll View everything is fine… Here is my code - any help would be really appreciated: -
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local func = require("functions") local http = require("httpwork") local widget = require( "widget" ) local group local scView local options= {} local c =0 local r = 0 for i = 1, 35 do options[i] = {} options[i].buttonPath = "Images/button" .. i .. ".png" options[i].x = (100 \* r + (200 \* math.ceil(i / 7) )) options[i].y = 30 + (80 \* c) if (i % 7) == 0 then c = 0 r = r + 1 else c = c + 1 end end local OptionClick = function(event) local resSelect = 0 local \_monType, \_monDesc if event.phase == "began" then local id = event.target.id print(id) if id == 16 then print("here") storyboard.gotoScene( "personal", "slideLeft", 800 ) end if id == 2 then storyboard.gotoScene( "bath", "slideLeft", 800 ) end if id == 13 then storyboard.gotoScene( "bed", "slideLeft", 800 ) end if id == 7 then storyboard.gotoScene( "activities", "slideLeft", 800 ) end if id == 5 then storyboard.gotoScene( "cream", "slideLeft", 800 ) end if id == 14 then storyboard.gotoScene( "sleep", "slideLeft", 800 ) end if id == 15 then storyboard.gotoScene( "movement", "slideLeft", 800 ) end if id == 19 then storyboard.gotoScene( "generalNote", "slideLeft", 800 ) end if id ==21 then \_monType = "RPIC" \_monDesc = "Resident Picture" resSelect = 1 end if id ==20 then \_monType = "CON" \_monDesc = "Consent" resSelect = 1 end if id ==17 then \_monType = "AM" \_monDesc = "Air Mattress" resSelect = 1 end if id ==10 then \_monType = "FL" \_monDesc = "Fluid Intake" resSelect = 1 end if id ==3 then \_monType = "FI" \_monDesc = "Food Intake" resSelect = 1 end if id ==6 then \_monType = "WE" \_monDesc = "Weight" resSelect = 1 end if id ==4 then \_monType = "BE" \_monDesc = "Behaviour" resSelect = 1 end if id ==9 then \_monType = "OB" \_monDesc = "Observations" resSelect = 1 end if id ==11 then \_monType = "BC" \_monDesc = "Bowel" resSelect = 1 end if id ==12 then \_monType = "IC" \_monDesc = "Intensive Care" resSelect = 1 end if id ==18 then \_monType = "ME" \_monDesc = "Meal Choice" resSelect = 1 end if id ==17 then \_monType = "AM" \_monDesc = "Air Mattress " resSelect = 1 end if id ==1 then \_monType = "Medical" \_monDesc = "Medical Visit " resSelect = 1 end if id ==8 then \_monType = "Health" \_monDesc = "Health Issue" resSelect = 1 end if resSelect == 1 then local options = { effect = "slideLeft", time = 800, params ={ MonType=\_monType, MonDescription = \_monDesc } } storyboard.gotoScene( "residentSelect", options ) end end end function scene:createScene( event ) group = self.view local prior\_scene = storyboard.getPrevious() storyboard.purgeScene( prior\_scene ) local head = func.CreateStandardHeader(1, \_G.StaffName) group:insert(head) local YourOptions = display.newImage("Images/YourOptions.png") YourOptions.x = (display.contentWidth / 2) -370 YourOptions.y = (display.contentHeight / 2) -270 group:insert(YourOptions) -- Create a ScrollView scView = widget.newScrollView { left = 0, top = 150, width = display.contentWidth, height = display.contentHeight, bottomPadding = 50, id = "onBottom", horizontalScrollDisabled = false, verticalScrollDisabled = true } for i = 1,26 do local but = display.newImage(options[i].buttonPath) but.id = i but.x = options[i].x but.y = options[i].y but:addEventListener( "touch", OptionClick ) scView:insert(but) end group:insert(scView) end -- "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
atte