Poor looping programming knowledge

private function thumbLoadComp (evt:Event) : void {
        
            var thumb:Thumb = new Thumb ();
            thumb.name = 'thumb' + num;
            
            thumbHolder.addChild (thumb);        
            thumbHolder.cacheAsBitmap = true;                        
        
            widthArray.push(thumb.width);
            
            if (num == 0){
                thumb.x = 0;
            }
            if (num == 1){
                thumb.x = (widthArray[0]);
                
            }
            if (num == 2){
                thumb.x = (widthArray[0] + widthArray[1]);
                
            }
            if (num == 3){
                thumb.x = (widthArray[0] + widthArray[1] + widthArray[2]);
               
            }
            if (num == 4){
                thumb.x = (widthArray[0] + widthArray[1] + widthArray[2] + widthArray[3]);
               
            }
        
            num++
            
            if (num < xml.item.(@folder == gallery).image.length ()) {
                loadThumb ();
            } else {
                num = 0;
            }         
            
        }

Just look at that rubbish. I know, I am ashamed, but I can’t refine the f***er to not look like a terrible example of programming.
What I’m trying to do is create a ‘belt’ with all the images loading from the left off into the distance towards the right. My progamming skills are admittedly rubbish, I cant work out how to write the code to make the first image load at x=0, then the next image to load when the first image finished, x=Image0._width, then the third to start after the second image ends, etc . Please help me learn…