swap image from cycle for

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

Anyone can help me ?

No one is answering because we don’t understand the question. Read this thread:

https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Come back with more information. You posted a lot of code which make it hard for people to digest what you’re trying to do. But more importantly, what are you expecting?  What are you seeing (screen shots are really helpful)? Are you getting any errors in your console log (those terminal/text command windows that open behind the simulator)? What version of Corona SDK are you using?

Rob

sorry…I try to explain better.

In my code i’ve 2 button widget (in “function press”) that loads different images in a cicle for. 

If i load the firt time images on cicld for the code run, but when i change images, the old images permains even if i removed all.

Nothing error, but on display i see the new Images and the latest images.

the variable “swap” signs the first time who the cicle for is loaded. If it is second time the code remove cicle for and load a new cicle.

in short, button 1 must load 2 image in cicle for and button 2 one or more different images.

This is the function who load and remove cicle for.

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 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 end end end

i’m using macbook pro and corona 2015.2646.

Anyone can help me ?

No one is answering because we don’t understand the question. Read this thread:

https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Come back with more information. You posted a lot of code which make it hard for people to digest what you’re trying to do. But more importantly, what are you expecting?  What are you seeing (screen shots are really helpful)? Are you getting any errors in your console log (those terminal/text command windows that open behind the simulator)? What version of Corona SDK are you using?

Rob

sorry…I try to explain better.

In my code i’ve 2 button widget (in “function press”) that loads different images in a cicle for. 

If i load the firt time images on cicld for the code run, but when i change images, the old images permains even if i removed all.

Nothing error, but on display i see the new Images and the latest images.

the variable “swap” signs the first time who the cicle for is loaded. If it is second time the code remove cicle for and load a new cicle.

in short, button 1 must load 2 image in cicle for and button 2 one or more different images.

This is the function who load and remove cicle for.

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 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 end end end

i’m using macbook pro and corona 2015.2646.