Slideshow with 3 categories - NEW

Hello everybody.

I’m trying to make a slideshow holding 3 images with 3 different categories. The images is loaded through an XML-file.

My xml looks like this: (the number after IMAGE[] indicates the category)

<?xml version="1.0" encoding="utf-8"?>
<SLIDESHOW SPEED="2">
    <IMAGE1 URL="images/1.jpg"/>
    <IMAGE1 URL="images/2.jpg"/>
    <IMAGE1 URL="images/3.jpg"/>
    <IMAGE1 URL="images/4.jpg"/>
    <IMAGE2 URL="images/5.jpg"/>
    <IMAGE2 URL="images/6.jpg"/>
    <IMAGE3 URL="images/7.jpg"/>
    <IMAGE3 URL="images/8.jpg"/>
    <IMAGE3 URL="images/9.jpg"/>
</SLIDESHOW>

Somehow my code just dont work. [COLOR=Black]What i want is that, if theres no more images in one category, it starts over again - and the other just keep going until theres no more, and then starts over again when they reach the last image.[/COLOR]

My AS3 looks like this: (i’m very new in as3, so i’m sure theres alot that can be improved)

var speed:Number;

var total1:Number;
var total2:Number;
var total3:Number;

var images1:XMLList;
var images2:XMLList;
var images3:XMLList;

var loaders_array1:Array = [];
var loaders_array2:Array = [];
var loaders_array3:Array = [];

var succes_counter1:Number = 0;
var succes_counter2:Number = 0;
var succes_counter3:Number = 0;

var playback_counter1:Number = 0;
var playback_counter2:Number = 0;
var playback_counter3:Number = 0;

var slideshow:Sprite = new Sprite();
var image_slides:Sprite = new Sprite(); 

var loader:URLLoader = new URLLoader();
    loader.load(new URLRequest("slideshow.xml"));
    loader.addEventListener(Event.COMPLETE, processXML);
    
function processXML (e:Event):void {
    var xml:XML = new XML(e.target.data);
    [email protected];
    
    images1=xml.IMAGE1;
    total1=images1.length();
    
    images2=xml.IMAGE2;
    total2=images2.length();
    
    images3=xml.IMAGE3;
    total3=images3.length();
    
    loadImages();
    trace("img1: " + total1 + " img2: " + total2 + " img3: " + total3);
}

function loadImages():void{
    for(var i1:Number = 0; i1 < total1; i1++){
        var url1:String = images1[i1][email protected];
        var loader1:Loader = new Loader();
        loader1.load(new URLRequest(url1));
        loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loaders_array1.push(loader1); 
    }
    
    for(var i2:Number = 0; i2 < total2; i2++){
        var url2:String = images2[i2][email protected];
        var loader2:Loader = new Loader();
        loader2.load(new URLRequest(url2));
        loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loaders_array2.push(loader2);
    }
    
        for(var i3:Number = 0; i3 < total2; i3++){
        var url3:String = images3[i3][email protected];
        var loader3:Loader = new Loader();
        loader3.load(new URLRequest(url3));
        loader3.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loaders_array3.push(loader3);
    }
}

function onComplete(e:Event):void{
    succes_counter1++;
    if(succes_counter1 == total1){
        startShow();
    }
}

function startShow():void{
    addChild(slideshow);
    slideshow.addChild(image_slides);
    
    nextImage();
}

knap_mc.addEventListener(MouseEvent.CLICK,nextBut);
function nextBut(event:MouseEvent):void {
    
    playback_counter1++;
    if (playback_counter1 == total1){
        playback_counter1 = 0;
    }
    
    playback_counter2++;
    if (playback_counter2 == total2){
        playback_counter2 = 0;
    }
    
    playback_counter3++;
    if (playback_counter3 == total3){
        playback_counter3 = 0;
    }
    
    nextImage();
}


function nextImage():void{

var image1:Loader = Loader(loaders_array1[playback_counter1]);
var image2:Loader = Loader(loaders_array2[playback_counter2]);
var image3:Loader = Loader(loaders_array3[playback_counter3]);

image_slides.addChild(image1);
image_slides.addChild(image2);
image_slides.addChild(image3);
image1.x = 264;
image1.y = 12;
image2.x = 495;
image2.y = 12;
image3.x = 726;
image3.y = 12;
}

I hope theres someone who can help me with this, cause i really dont know what to do. Thank you in advance!