Hi …
i am sure there are many ways to do it …but i made this one for you… it might not optimal but at least you can start with it .
[lua]
local widget = require( “widget” )
myImages = {“image1.jpg”, “image2.jpg”, “image3.jpg” } – name of images
currentImageIndex = 1 – this is index to track your current image
– display the first image
myCurrentImage = display.newImage( myImages[1])
myCurrentImage.x = 150
myCurrentImage.y = 100
– Function to handle back and forward buttons
local function handleButtonEvent( event )
if ( “ended” == event.phase ) then
if event.target.id == “back” and currentImageIndex > 1 then
print( “Back” )
myCurrentImage:removeSelf()
myCurrentImage = nil
myCurrentImage = display.newImage( myImages[currentImageIndex - 1])
myCurrentImage.x = 150
myCurrentImage.y = 100
currentImageIndex = currentImageIndex - 1
elseif event.target.id == “fwd” and currentImageIndex < 3 then
print( “fwd” )
myCurrentImage:removeSelf()
myCurrentImage = nil
myCurrentImage = display.newImage( myImages[currentImageIndex + 1])
myCurrentImage.x = 150
myCurrentImage.y = 100
currentImageIndex = currentImageIndex + 1
end
end
end
local back = widget.newButton
{
left = 0,
top = 200,
id = “back”,
label = “Go Back”,
onEvent = handleButtonEvent
}
local fwd = widget.newButton
{
left = 120,
top = 200,
id = “fwd”,
label = “Go to forword”,
onEvent = handleButtonEvent
}
[/lua]