media.selectPhoto() is bugging ?

Well, my application is running normally when I do not insert a photo. If I click to insert a photo, put a photo and try to open a function it executes only the first commands of the function, it does not delete the BG and add the new BG. Does anybody have any idea why this is happening? I’ve been trying to solve this for about 3 days, I’ve read it, I read it again and again and again and I never find out what the problem is …

In the code.lua :

 function Selecionar(event, tap) local function onComplete( event ) local photo = event.target if photo ~= nil then photo.x = centerX + 15 photo.y = centerY photo.width = 250 photo.height = 190 photo:rotate( 90 ) print( "photo w,h = " .. photo.width .. "," .. photo.height ) group:insert ( photo ) AbrirFoto:removeSelf() end end if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource=media.PhotoLibrary, listener=onComplete } ) else native.showAlert( "FOMT", "Não existe imagens em seu dispositivo.", { "OK" } ) end end AbrirFoto = display.newImage("images/addIMAGEM.png") AbrirFoto.width = AbrirFoto.width/7 AbrirFoto.height = AbrirFoto.height/7 AbrirFoto.x = centerX + 25 AbrirFoto.y = centerY AbrirFoto:rotate ( 90 ) AbrirFoto:addEventListener("tap", Selecionar)

after in the same code.lua

 function Informacoes() transition.cancel() -- To cancel all transitions botao1.isVisible = false botao2.isVisible = false botao3.isVisible = false botao4.isVisible = false if QtdeMovimentos \>= 2 then Bbotao1.isVisible = false Bbotao2.isVisible = false Bbotao3.isVisible = false Bbotao4.isVisible = false end if QtdeMovimentos == 3 then Cbotao1.isVisible = false Cbotao2.isVisible = false Cbotao3.isVisible = false Cbotao4.isVisible = false end botaoInfo.isVisible = false Fim.isVisible = false backup.isVisible = false if photo == nil then AbrirFoto:removeSelf() end if bg.x == display.contentWidth then -- Only verify if bg exist bg:removeSelf() bg = nil end local \_W = display.contentWidth local \_H = display.contentHeight local bg bg = display.newImageRect("images/fundohCIN.png", display.actualContentWidth, display.actualContentHeight) bg.x = display.contentCenterX bg.y = display.contentCenterY group:insert(bg) end botaoInfo = display.newImage("images/INFO.png") botaoInfo.width = display.contentWidth/8.5 botaoInfo.height = display.contentHeight/13.5 botaoInfo.x = rightMarg - botaoInfo.height/2 botaoInfo.y = centerY - 15 botaoInfo:rotate( 90 ) botaoInfo:addEventListener("tap", Informacoes) group:insert ( botaoInfo )

The function “Informacoes” not open normally