Hi…I’m trying change images in cycle for, but my code is not run correctely. The images removed remains on display.
What’s the problem ?
Thanks for your help.
local widget = require "widget" local swap = "0" local t = {} local button = {} local nome local scroll2 = widget.newScrollView { left = 0, top = 120, width = display.contentWidth , height = display.contentHeight , hideBackground = true, topPadding = 0 , bottomPadding = display.contentHeight -100, verticalScrollDisabled = false, listener = scrollListener, scrollWidth = display.contentWidth, scrollHeight = display.contentCenterY , } local function load() if nome == "save" then button[1] = {image = "ggg.jpg"} button[2] = {image = "ggg.jpg" } elseif nome == "remove" then button[1] = {image = "ttt.jpg" } end if swap == 1 then for i = 1,#button do t[i] = display.newImageRect( button[i].image,100,100 ) t[i].x = display.contentCenterX t[i].y = i\*120 scroll2:insert(t[i]) end elseif swap \> 1 then for i= 1, #button do t[i]:removeSelf() t[i] = nil end for i = 1,#button do t[i] = display.newImageRect( button[i].image,100,100 ) t[i].x = display.contentCenterX t[i].y = i\*120 scroll2:insert(t[i]) end end end local function press(event) if (event.phase == "began") then swap = swap + 1 local id = event.target.id if id == "load" then nome = "save" print (swap) load() elseif id == "remove" then print (swap) nome = "remove" load() end end end local remove = widget.newButton { label = "load image", id = "remove", onEvent = press, emboss = false, --properties for a rounded rectangle button... shape="roundedRect", width = 300, height = 17, cornerRadius = 2, fillColor = { default={ 1,0.4,0 }, over={ 1,0.4,0 } }, } -- Center the button remove.x = display.contentCenterX remove.y = display.contentCenterY- 200 local emailSave = widget.newButton { label = "load image", id = "load", onEvent = press, emboss = false, --properties for a rounded rectangle button... shape="roundedRect", width = 300, height = 17, cornerRadius = 2, fillColor = { default={ 1,0.4,0 }, over={ 1,0.4,0 } }, } -- Center the button emailSave.x = display.contentCenterX emailSave.y = display.contentCenterY- 220