remove the prior image when press the button.

Can anyone help me slove this, I want to remove the prior image when press the button. full code is below.:
local shapes_img ={}
local num_of_imgs = 9
local index_img = 1


local prevx = 0
local prevy = 0
–function new()
local localGroup = display.newGroup()

local ImageGroup = display.newGroup()

local background = display.newRect(0,0,display.contentWidth,display.contentHeight)
background :setFillColor(255,255,255) --white color
localGroup:insert(background)

shapes_img = {“images/square.png”,“images/triangle.png”,“images/circle.png”,
“images/rectangle.png”,“images/star.png”,“images/trapezoid.png”,
“images/diamond.png”,“images/star.png”,“images/pentagon.png”}

function show_Shapes()

local shapes_name = display.newImageRect(shapes_img[index_img],150,150,true)
shapes_name.x = display.contentWidth/2
shapes_name.y = display.contentHeight/2
ImageGroup:insert(shapes_name)
shapes_name:addEventListener(“touch”, onTouch)

end

function onTouchLeftArrow (event)

if index_img < 2 then

index_img = 9

else

index_img = index_img - 1
end
print(“index_img…”…index_img)

show_Shapes()
end

local left_arrow = display.newImageRect(“images/left_arrow.png”,100,80)
left_arrow.x = 50
left_arrow.y = display.contentHeight-50
localGroup:insert(left_arrow)

left_arrow :addEventListener( “tap” , onTouchLeftArrow )

function onTouchLeftRight(event)

if index_img > 9 then

index_img = 1

else

index_img = index_img + 1
end
print(“index_img…”…index_img)

local count = display.getCurrentStage().numChildren
print( "Number of objects on the screen = " … count )

show_Shapes()

end

local right_arrow = display.newImageRect(“images/right_arrow.png”,100,80)
right_arrow.x = display.contentWidth-50
right_arrow.y = display.contentHeight-50
localGroup:insert(right_arrow)

right_arrow :addEventListener( “tap” , onTouchLeftRight )

function onTouch( event )
local t = event.target

– Print info about the event. For actual production code, you should
– not call this function because it wastes CPU resources.
–printTouch(event)

local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )

– Spurious events can be sent to the target, e.g. the user presses
– elsewhere on the screen and then moves the finger over the target.
– To prevent this, we add this flag. Only when it’s true will “move”
– events be sent to the target.
t.isFocus = true

– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if “moved” == phase then
– Make object move (we subtract t.x0,t.y0 so that moves are
– relative to initial grab point, rather than object “snapping”).
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

– Important to return true. This tells the system that the event
– should not be propagated to listeners of any objects underneath.
return true
end [import]uid: 22631 topic_id: 20733 reply_id: 320733[/import]

[code]
local shapes_img ={}
local num_of_imgs = 9
local index_img = 1


local prevx = 0
local prevy = 0
–function new()
local localGroup = display.newGroup()

local ImageGroup = display.newGroup()

local background = display.newRect(0,0,display.contentWidth,display.contentHeight)
background :setFillColor(255,255,255) --white color
localGroup:insert(background)

shapes_img = {“images/square.png”,“images/triangle.png”,“images/circle.png”,
“images/rectangle.png”,“images/star.png”,“images/trapezoid.png”,
“images/diamond.png”,“images/star.png”,“images/pentagon.png”}

function show_Shapes()

local shapes_name = display.newImageRect(shapes_img[index_img],150,150,true)
shapes_name.x = display.contentWidth/2
shapes_name.y = display.contentHeight/2
ImageGroup:insert(shapes_name)
shapes_name:addEventListener(“touch”, onTouch)

end

function onTouchLeftArrow (event)

if index_img < 2 then

index_img = 9

else

index_img = index_img - 1
end
print(“index_img…”…index_img)

show_Shapes()
end

local left_arrow = display.newImageRect(“images/left_arrow.png”,100,80)
left_arrow.x = 50
left_arrow.y = display.contentHeight-50
localGroup:insert(left_arrow)

left_arrow :addEventListener( “tap” , onTouchLeftArrow )

function onTouchLeftRight(event)

if index_img > 9 then

index_img = 1

else

index_img = index_img + 1
end
print(“index_img…”…index_img)

local count = display.getCurrentStage().numChildren
print( "Number of objects on the screen = " … count )

show_Shapes()

end

local right_arrow = display.newImageRect(“images/right_arrow.png”,100,80)
right_arrow.x = display.contentWidth-50
right_arrow.y = display.contentHeight-50
localGroup:insert(right_arrow)

right_arrow :addEventListener( “tap” , onTouchLeftRight )

function onTouch( event )
local t = event.target

– Print info about the event. For actual production code, you should
– not call this function because it wastes CPU resources.
–printTouch(event)

local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )

– Spurious events can be sent to the target, e.g. the user presses
– elsewhere on the screen and then moves the finger over the target.
– To prevent this, we add this flag. Only when it’s true will “move”
– events be sent to the target.
t.isFocus = true

– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if “moved” == phase then
– Make object move (we subtract t.x0,t.y0 so that moves are
– relative to initial grab point, rather than object “snapping”).
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

– Important to return true. This tells the system that the event
– should not be propagated to listeners of any objects underneath.
return true
end
[blockcode] [import]uid: 22631 topic_id: 20733 reply_id: 81421[/import]

Is the idea to have one image that appears to change?

If so, would a spritesheet not be easier?

If you switch the above to plug and play or provide a sample download someone may be able to assist but this is quite long and cannot be run by anyone but you in its current form.

Peach [import]uid: 52491 topic_id: 20733 reply_id: 81447[/import]