Intelligent XML Image Gallery

Hi all!!

Before I continue working with this, I was thinking some clever mind had a solution to this.

What I want to achieve is to have a smart dynamic image gallery that reads the nodes from an xml sheet in order to set the number of images to be loaded in the container that I have on stage.

Then when the user clicks the two hit areas I have (prev & next), the script checks for the number in the XMLList that is currently being targeted, and loads the next or the previous image in the sequence of images written in the xml file. And also loops it when the last image in the list has been pressed!

This is what I have so far.

var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
	xml = XML(event.target.data);
	xmlList = xml.children();
	{
		imageLoader = new Loader();
		imageLoader.load(new URLRequest(xmlList[0].attribute("source")));
		container_mc.addChild(imageLoader);
	}
}
prev_btn.addEventListener(MouseEvent.CLICK, prev);

function prev(event:MouseEvent):void
{
	trace("click prev");
}

next_btn.addEventListener(MouseEvent.CLICK, next);

function next(event:MouseEvent):void
{
	trace("click next");
}

Can I store an array from the nodes of the xml list, so it automatically starts from the beginning when the last image has been chosen? Or does someone have a better solution to the issue?

I was planning on writing something like, for(var i:int = 0; i < xmlList.length(); i++) but then I would have to have some sort of if statement in there and confuse everything :slight_smile:

Oh well, hope someone has had this problem solved before me and is willing to share his/her experience with me!

Thanks in advance

/rundevo

This is a AS 2 code I got somewhere, and its exactly what I want to do, apart from using XML to load the images!

Maybe it can help someone to help me since I dont know much AS2.

var slideInfoLV:LoadVars = new LoadVars();

slideInfoLV.onLoad = function (success) {
	if (success) {
		slideCounter();
	} else {
		frameNum.text = "error";
	}
}

slideInfoLV.load("vars/slide_info.txt");

var curFrameNum:Number = 0;

function loadFrame() {
	_level0.myMCL.loadClip("frames/frames" + curFrameNum + ".jpg", this.framesMC);
	_level0.myLV.load("frames/frames" + curFrameNum + ".txt");
}

function slideCounter() {
	frameNum.text = ("frame style " + (curFrameNum + 1) + " of " + Number(slideInfoLV.totalFrames));
}

this.nextSlideBtn.onRelease = function() {
	
	if (curFrameNum < Number(slideInfoLV.totalFrames) - 1) {
		curFrameNum ++;
	} else {
		curFrameNum = 0;
	}
	loadFrame();
	slideCounter();
}
this.prevSlideBtn.onRelease = function() {
	
	if (curFrameNum == 0) {
		curFrameNum = Number(slideInfoLV.totalFrames) - 1;
	} else {
		curFrameNum --;
	}
	loadFrame();
	slideCounter();
	
}

Cheers!

/rundevo