Hi all,
I’ve got an interesting one for ya. How do I make a random XML auto gallery. The actionscript is for my auto gallery, which loads and changes every 15 seconds. How do I make it so that it loads from the XML file randomly?!
Any help would be much appreciated! Thanks guys and gals.
See code below…
// set up variable and constants
var pathToPics = new String();
var pArray = new Array();
var tArray = new Array();
var fadeSpeed = 20;
var pIndex = 0;
// change photo prototype function
MovieClip.prototype.changePhoto = function(d) {
this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {
this.pIndex += this.pArray.length;
}
this.onEnterFrame = fadeOut;
};
// fade pictures out prototype
MovieClip.prototype.fadeOut = function() {
if (this.photo._alpha>this.fadeSpeed) {
this.photo._alpha -= this.fadeSpeed;
} else {
this.loadPhoto();
}
};
// load photo prototype
MovieClip.prototype.loadPhoto = function() {
var p = this.photo;
p._alpha = 0;
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
this.onEnterFrame = loadMeter;
};
// preloader function for pictures
MovieClip.prototype.loadMeter = function() {
var l, t, per;
l = this.photo.getBytesLoaded();
t = this.photo.getBytesTotal();
per = Math.round((l/t)*100);
loadBar._visible = 1;
if (t>0 && t == l) {
this.onEnterFrame = fadeIn;
loadBar._visible = 0;
} else {
loadBar._xscale = per;
}
};
// fade in pictures prototype
MovieClip.prototype.fadeIn = function() {
if (this.photo._alpha<100-this.fadeSpeed) {
this.photo._alpha += this.fadeSpeed;
} else {
this.photo._alpha = 100;
this.onEnterFrame = null;
}
};
// set timing for the photo change
setInterval(this,"changePhoto", 15000, 1)
// set up XML
var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success) {
if (success) {
var gallery = this.firstChild;
pathToPics = gallery.attributes.path;
for (var i = 0; i<gallery.childNodes.length; i++) {
tArray.push(gallery.childNodes*.attributes.title);
pArray.push(gallery.childNodes*.attributes.source);
}
loadPhoto();
} else {
title_txt.text = "Error!";
}
};
// XML gallery file
gallery_xml.load("autogallery.xml");
In addition, is there a way to stop possible recurrsion? This would be excellent to stop the same image being called twice in a row…
Ads.