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
[lua]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[/lua] [import]uid: 69642 topic_id: 13878 reply_id: 313878[/import]