I want to programatically setup a certain number of buttons by rows and columns. The following code shows the buttons on the screen, button when I press them, the function btnPress is not called. Any ideas would be greatly appreciated. (I’m using the ui.lua from the Ghosts and Monsters sample code.)
local ui = require("ui")display.setStatusBar(display.HiddenStatusBar) local mainscreen = function( ) local background = display.newImage( "black.png") local wd = display.contentWidth local ht = display.contentHeight background.x = wd / 2 background.y = ht / 2 local btns = {} local row = 1 local col = 1 local img_fle = "level.png" local btn_nme for i = 1, 20 do btns[i] = ui.newButton { defaultSrc = img_fle, defaultX = 60, defaultY = 60, onEvent = btnPress, id = i, align = "center", text = i, size = 12, emboss=true } btns[i].x = wd / 6 * col btns[i].y = ht / 5 * row if col == 5 then col = 1 row = row + 1 else col = col + 1 end local img_fle = "level.png" endendlocal btnPress = function( event ) print("Button Pressed" .. event.id )endmainscreen() [import]uid: 13201 topic_id: 5961 reply_id: 305961[/import]