# Poor looping programming knowledge

**URL:** <https://forum.kirupa.com/t/poor-looping-programming-knowledge/254386>\
**Category:** flash\
**Created:** [March 11, 2008, 3:18pm UTC](https://forum.kirupa.com/t/poor-looping-programming-knowledge/254386 "2008-03-11T15:18:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daidai](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/daidai/32/3087_2.png) [@daidai](https://forum.kirupa.com/u/daidai)\
**Post date:** [March 11, 2008, 3:18pm UTC](https://forum.kirupa.com/t/poor-looping-programming-knowledge/254386/1 "2008-03-11T15:18:49Z")

</div>

```php
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…
