Problems / understanding - buttons and callbacks

Ignore that, I am blind.

Other elements in the scene - including BG image - were being added ontop of everything else, because I had mistakenly removed *their* group:insert’s.

IT WORKS!!

Thank you so much, you’ve opened epic doors for me here. If anyone on this thread finds themselves in the North West of the UK any time, demand beers from me.

 

Great, glad you got it working!

[oops, replied to an earlier part of the thread instead of the bottom]

  • Andrew

Hi all,

Sorry to ask, what is probably, an obvious question but I am struggling with this - I need to pass ‘event’ to a function that controls which picture to show depending upon which button is pressed.

function startPictureViewer() local function back(backButton, galleryIndex) backButton:removeSelf() backButton = nil local i = 1 while i\< 20 do if galleryIndex[i] ~= nil then galleryIndex[i]:removeSelf() galleryIndex[i] = nil end i = i + 1 end mainMenu.startMainMenu() end local function viewPicture(galleryIndex, backButton) local function closePicture() end --local buttonPressed = event.target.id for k, v in pairs(event) do print(k, v) end backButton.onRelease = function() closePicture() end local picture = display.newImage(galleryIndex[buttonPressed]) picture.x = 100 picture.y = 0 end settingsIndex = splashScreen.returnSettingsIndex() local galleryIndex = {} local filesToOpen = {} local backButton = widget.newButton { id = 1, style = "backLarge", label = "Back", fontSize = settingsIndex.fontSize, width = 120, } backButton.onRelease = function() back(backButton, galleryIndex) end backButton.x = 70 backButton.y = 55 local title = display.newText("Image Gallery", 70, 100, native.systemFont, 30) title:setTextColor(0, 0, 0) local jsonPath = system.pathForFile("DownloadedGalleryIndex.json", system.DocumentsDirectory) local f = io.open(jsonPath, "r") if f == nil then f = io.open(jsonPath, "w") local jsonTestArray = {} jsonTestArray["records"] = {} c = json.encode(jsonTestArray) f:write(c) end f:close() f = io.open(jsonPath, "r") local c = f:read ("\*a") local jsonFile = json.decode(c) local j = 1 local k = 0 local i = 1 while i \< 20 do if jsonFile["records"][i] ~= nil then galleryIndex[i] = widget.newButton { id = i, style = "redLarge", label = jsonFile["records"][i], fontSize = settingsIndex.fontSize, width = 300 } filesToOpen[i] = jsonFile["records"][i] galleryIndex[i].x = 300\*k+160 galleryIndex[i].y = j\*50 + 140 galleryIndex[i].onRelease = function() viewPicture(galleryIndex, backButton) end end if j == 10 then k = k + 1 j = 1 end j = j + 1 i = i + 1 end end

Anybody got any ideas?