Hello,
I am - obviously - new to Corona and to programming in general. I am trying to figure out if Corona is suitable for my first iOS project.
My specific question here is in regards to using Director in combination with Listview. I used (maybe abused) the Coffee TableView example to create a list from a table which generates buttons in every row.
I would like to change a global variable (_G.fileName) before switching back to the previous screen. It works when I hard-code a new file name into the buttonSelectRelease function, but how do I let the function know the correct file name for each button in my list?
Thanks for your help.
Best, Oliver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | local scrollView = require("scrollView") local util = require("util") local sequences = {} sequences[1] = {} sequences[1].name = "Salida" sequences[1].desc = "Basic 8 Step to the woman's cross." sequences[1].fileName = "salida.json" sequences[2] = {} sequences[2].name = "Forward Ochos" sequences[2].desc = "Forward 8's from the woman's cross." sequences[2].fileName = "forward-ochos.json" buttonSelectRelease = function ( event ) if event.phase == "ended" then _G.fileName = sequences[event.target.id].fileName director:changeScene( "screenAni", "moveFromLeft" ) end end -- Create a list with no background, allowing the background image to show through local topBoundary = display.screenOriginY + 40 local bottomBoundary = display.screenOriginY + 0 -- create the list of items myList = tableView.newList{ data=sequences, default="listSelectBg.png", top=topBoundary, bottom=bottomBoundary, callback = function( row ) local g = display.newGroup() local name = display.newText( row.name, 0, 0, native.systemFontBold, 14 ) name:setTextColor(255, 255, 255) g:insert(name) name.x = name.width*0.5 + 10 name.y = 40 local desc = display.newText( row.desc, 0, 0, native.systemFont, 12 ) desc:setTextColor(180,180,180) g:insert(desc) desc.x = desc.width*0.5 + 10 desc.y = name.y + name.height + 5 local buttonSelect = ui.newButton{ default = "whiteButton.png", over = "whiteButtonOver.png", onRelease = buttonSelectRelease, text = "Select", size = 12, emboss = false } g:insert(buttonSelect) buttonSelect.x = 280 buttonSelect.y = (name.y + desc.y) / 2 buttonSelect.alpha = 0.8 return g end } local function scrollToTop() myList:scrollTo(topBoundary-1) end |