Apple AS2 XML Slideshow

Some few tricks on simple flash xml slideshow on Action Script 2.

1. The Slideshow


function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
desc_txt2.text = description2[0];
btnLinks(0);
slideshow();
}
}

function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
desc_txt2.text = description2[p];
btnLinks(p);
slideshow();
}
}
}

function prevImage() {
if (p>0) {
p–;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
desc_txt2.text = description2[0];
btnLinks(p);
slideshow();
}
}

function slideshow() {
if (stopit) {
myInterval = setInterval(pause_slideshow, delay);
} else {
clearInterval(myInterval);
}

function pause_slideshow() {
clearInterval(myInterval);
if (p == (total-1)) {
p = 0;
firstImage();
} else {
nextImage();
}
}
}

function pause_slideshow() {
stopit = false;
clearInterval(myInterval);
}

function btnLinks(p) {
btnlink.onRelease = function() {
getURL(link[p]);
trace(link[p]);
}
}

2. The Load XML

function loadXML(loaded) {
if (loaded) {
trace("file loaded!");
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;
for (i=0; i
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
description2[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
link[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
}
firstImage();
} else {
trace("file not loaded!");
}
}

var stopit = true;
var myInterval;
var delay = 5000;
var p = 0;
var total;
var image = new Array();
var description = new Array();
var description2 = new Array();
var link = new Array();

var xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“sample.xml”);

3. The Retrival

this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (picture._alpha<100) {
picture._alpha += 4;
}
}
};

Source :
FLA File
XML Sample
AS2

Version2:
FLA File
XML Sample

Leave a Reply