External image display AS3

Hello, I am having a bit of difficulty with what I thought would be a simple animation, I have spent an embarrassingly long time on this and gone through several versions of the implementation, the most successful one being below. But alas I have reached a stage where I need to ask for help.

The goal is to create something like the effect on the home page of www.interfusionuk .com where the images are changing one at a time in succession except for mine there will be more than 2 sets of images probably 5 sets, and I will have different sets for different pages hence the reason why I wanted to load the images externally from an xml file. Also there will be no space between the images.

Now the result I have so far is that the images are loading to the stage but they are loaded on top of each other. The problem is that the loader widths are not being read, they are all 0 as found from the trace output. I tried using the lastWidth variable previously which you will see in the event handler but that is out of scope when the function returns to the main program.

I’m pretty new to AS3 and am still trying to get my head around it, apologies for the length of this post but I feel that it will be easier for people to provide help if they know as much as possible.

Thanks


import fl.transitions.Tween; 
import fl.transitions.easing.*;
import fl.transitions.TweenEvent; 

import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;


var loader = new Array();
var lastWidth:int;



var myXML:XML;
var urlRequest:URLRequest = new URLRequest();
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("xml/portfolio.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);

for (var i:int = 0; i<myXML.*.length(); i++){
trace("My image number is " + (i+1) + ", it's title is " + myXML.pic* + " and it's URL is " + myXML.pic*);

var urlRequest:URLRequest = new URLRequest(myXML.pic*);

loader*=new Loader();
loader*.load(urlRequest);
loader*.alpha = 0.0;

};

doIt();
}


function doIt():void{
//var totalWidth:int =0;
//var previousWidth:int =0;

for (var i:int = 0; i<myXML.*.length(); i++){


if(i==0){
    loader*.x = 0;
    }
    
    else{
        
loader*.x =  loader[i-1].x + loader[i-1].width;
trace(lastWidth);
    
    }
    
    addChild(loader*);
    
    loader*.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
    
    

var myTween:Tween = new Tween(loader*, "alpha", Strong.easeIn , 0, 100, 2, true);
//myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
    };
    }
    
    /*function onFinish(e:Event){  // This bit will be used to create a delay after the first set load
        for (var y:int = 0 ; y<20 ; y++){};
        
        }*/
        
        function onImageLoaded(e:Event){
        lastWidth = e.target.width;
        
        }

<portfolio>
<pic>/xml/home1.jpg</pic>
<pic>/xml/home2.jpg</pic>
<pic>/xml/home3.jpg</pic>
</portfolio>