Hello, I have problems to rescue the ID of dynamic buttons (myButtonGroup.ID = i)
Not work it : print ("Botton ID: "… tostring(self.ID)) and self[1].alpha=0.3
Can you help me please?
[code]
– main.lua
CONTENIDO = display.newGroup();
MC_LISTADO = display.newGroup();
CONTENIDO:insert(MC_LISTADO);
function paint()
local widget = require “widget”
local scroller = widget.newScrollView{
width = 320,
height = 480,
scrollWidth = 50,
scrollHeight = 1000,
bgColor = {0,0,0,0}
}
–BUTTON FUNCTION
function accionBoton( event )
if event.phase == “moved” then
local dx = math.abs( event.x - event.xStart )
local dy = math.abs( event.y - event.yStart )
if dx > 5 or dy > 5 then
scroller:takeFocus( event )
end
end
if event.phase == “press” then
print( “Button press” )
self[1].alpha=0.3 --<<<< ERROR: attempt to index global ‘self’ (a nil value)
end
if event.phase == “release” then
print ("Botton ID: "… tostring(self.ID)) --<<<< ERROR: attempt to index global ‘self’ (a nil value)
print( “Button release” )
end
return true
end
local BtnList={}
local myButtonGroup = display.newGroup() --Botones
for i=1, 8 do
–BOTÓN
myButtonGroup.ID=i --<< how to rescue this data?
botonImagen = widget.newButton{
id = “button0”,
width = 80, height = 80,
default = “imagenes/btn_off.jpg”,
over = “imagenes/btn_on.jpg”,
onEvent = accionBoton,
}
botonImagen.x=60
botonImagen.y=155*i-75
myButtonGroup:insert(botonImagen);
BtnList[i] = myButtonGroup
scroller:insert(myButtonGroup);
end
–Insert in group “MC_LISTADO”
MC_LISTADO:insert( scroller.view )
end
paint()
[/code] [import]uid: 121547 topic_id: 31767 reply_id: 331767[/import]