Hi!
This code should work:
PHP Code:
var myPlace:Loader = new Loader();
myPlace.x=50.0
myPlace.y=50.0
addChild(myPlace);
var theImages:Array=new Array("mercedes1","mercedes2","mercedes3");
var currentImage:Number;
prevImage.addEventListener(MouseEvent.CLICK,prevClicked,false,0,true);
nextImage.addEventListener(MouseEvent.CLICK,nextClicked,false,0,true);
myPlace.load(new URLRequest(theImages[0] + ".jpg"));
function prevClicked(event:MouseEvent):void
{
currentImage--;
if (currentImage < 0) {
currentImage = theImages.length - 1;
}
myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));
}
function nextClicked(event:MouseEvent):void
{
currentImage++;
if (currentImage >= theImages.length)
{
currentImage = 0;
}
myPlace.load(new URLRequest(theImages[currentImage] + ".jpg"));
}
all you need is the index 'currentImage' (not 'previousImage' or 'currentImageName').
That's the index you increment or decrement to switch among the images.
I've changed the line
PHP Code:
if (currentImage>=3)
{
currentImage = 0;
}
in
PHP Code:
if (currentImage >= theImages.length)
{
currentImage = 0;
}
so anytime you want you can add or remove items from the array without changing any other line of code.
Hope it's been useful
Bookmarks