Problem with finding width of an image



package {
    
    import flash.display.*;
    import flash.text.*;
    import caurina.transitions.*;
    import flash.events.*;
    import flash.net.*;
    
    public class GalleryDisplay extends Sprite {
        
        public var gContainer:Sprite = new Sprite ();
        public var thumbHolder:Sprite = new Sprite ();
        public var thumbBack:Shape = new Shape ();
        private var thumbLoader:Loader;        
        private var xml:XML;        
        private var gallery:String;
        private var num:int = 0;
        public var pos:int;
                
        public function GalleryDisplay (src:XML,gal:String) {        
            
            xml = src;            
            
            thumbHolder.graphics.beginFill (0xCCCCCC);
            thumbHolder.graphics.endFill ();            
            
            gallery = gal;            
            thumbHolder = null;
            thumbHolder = new Sprite ();
            gContainer.addChild (thumbHolder);
            loadThumb ();
            addChild(gContainer);        
        }
        
        private function loadThumb () : void {
            thumbLoader = new Loader ();            
            thumbLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, thumbLoadProg);
            thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoadComp);
            var thumbURL:URLRequest = new URLRequest ('images/' + gallery + '/' + xml.item.(@folder == gallery).image[num].@img);
            thumbLoader.load(thumbURL);
        }
        
        private function thumbLoadProg (evt:ProgressEvent) : void {
        }
        
        private function thumbLoadComp (evt:Event) : void {
            
            var thumb:Thumb = new Thumb (thumbLoader, 
                                         xml.item.(@folder == gallery).image[num].@img, 
                                         gallery, 
                                         num);
            thumb.name = 'thumb' + num;

            // thumb.x values can be read here
            // thumb.x = num * (thumb.width + 20);
            // var widthArray:Array = new Array ();
            // widthArray.push (thumb.width);
            
            thumbHolder.addChild (thumb);        
            thumbHolder.cacheAsBitmap = true; 

            num++
            
            if (num < xml.item.(@folder == gallery).image.length ()) {
                loadThumb ();
            } else {
                num = 0;
            }
        }
    }
}




This GalleryDisplay.as loads in xml images and displays them. What I need to do is display them horizontally, so the second image starts to the immediate right of the first image. Normally I would use

thumb.x = num * (thumb.width + 20);

but the problem is that only works if the images are all the same size. But for this project they aren’t. I have tried to add the thumb.width’s to an Array but the array just adds the values to [0] not increasing and therefore becomes useless.

var widthArray:Array = new Array ();
widthArray.push (thumb.width);

Can anyone please help me solve this. Thanks

p.s. I cant seem to find the option to post ActionScript code only

 code, how do you do it?