var xmlRequest:URLRequest = new URLRequest("xmlData.xml");
var xmlLoader:URLLoader = new URLLoader(xmlRequest);
var imgData:XML; //conterrà XML data
var imageLoader:Loader;
//Used to get image details from the XML file for the Loader
var rawImage:String;
var rawH:String;
var rawW:String;
//Actual image
var imgNum:Number = 0;
//Deelay to Load from an image to another
var checkSec:Timer = new Timer(100);
//number of images that will be present
var numberOfChildren:Number;
//master_mc is the desktop that we use as background
master_mc.addEventListener(MouseEvent.CLICK, nextImgF);
master_mc.buttonMode = true; //show the hand instead of arrow
//When mouse click, increase imgNum to update the actual image
function nextImgF(event:MouseEvent):void{
checkSec.addEventListener(TimerEvent.TIMER, checkerF);
imgNum++;
}
//Manage the image Loading and the restart from the beginning of the gallery
function checkerF(event:TimerEvent):void{
// - If it's the first image, then call packagedF to Load images from the XML file
// - else, if we aren't at the end of the images (or charging not the first image)
// unload the previous image (unload) and call packageF to load a new image
// - else if we've finished all the images, then start from the first image.
if(imgNum == 0){
packagedF();
} else if(imgNum < numberOfChildren){
imageLoader.unload();
packagedF();
} else{
imageLoader.unload();
imgNum = 0;
packagedF();
}
}//checkerF
//When the movie loading is completed, add file from XML file to imgData
xmlLoader.addEventListener(Event.COMPLETE, xmlLoadedF);
function xmlLoadedF(event:Event):void{
checkSec.start();
checkSec.addEventListener(TimerEvent.TIMER, checkerF);
imgData = new XML(event.target.data); //content of the XML file
}
// - - - -
//Get the image (A SINGLE IMAGE! THE # imgNum!) from the XML file
//and send to master_mc
function packagedF():void{
checkSec.removeEventListener(TimerEvent.TIMER, checkerF);
rawImage = imgData.image[imgNum].imgUrl; //<imgURL></imgURL> è un elemento del file XML
numberOfChildren = imgData.*.length(); //number of images
//get <imgH> and <imgW>
rawH = imgData.image[imgNum].imgH;
rawW = imgData.image[imgNum].imgW;
//create a Loader to load the image, added to the master_mc as a child
imageLoader = new Loader();
imageLoader.load(new URLRequest(rawImage));
master_mc.addChild(imageLoader);
//centrare l'immagine
imageLoader.x = (stage.stageWidth - Number(rawW))/2;
imageLoader.y = (stage.stageHeight - Number(rawH))/2;
}//packagedF