In this code for a credits screen:
[lua]local creditsbackground = display.newImageRect(“Credits.png”, 480, 320)
creditsbackground.x = display.contentWidth / 2; creditsbackground.y = display.contentHeight / 2
creditsitems:insert( creditsbackground )
local backRelease = function(event)
media.playEventSound( buttonsound )
creditsitems:removeSelf() --this removes the entire scene and the next line goes back to menu
menu()
end
local back = ui.newButton{
default = “back.png”,
over = “back2.png”,
onRelease = backRelease
}
back.x = 223; back.y = 288
creditsitems:insert( back )[/lua]
calling creditsitems:removeSelf() removes everything, even the back button that was added after the backRelease function (which is the desired behavior).
However if I try to manipulate back (say back.alpha = 0) inside the backRelease function I get the attempted to index a nil global value error, since apparently local back hasn’t been declared yet.
HOWEVER if I do the same but instead of calling back directly I do creditsitems[2].alpha = 0 it works.
So how can “back” be in the creditsitems group without having been declared? Right now I’m using the workaround of calling every item by its parent group number, but I’d like to know why this happens. Thanks.
[import]uid: 10835 topic_id: 4296 reply_id: 304296[/import]