Hey there, I’ve been searching forums + Google all day, and can’t quite get this working.
Scotty helped me customize the XML photo gallery years ago and I’m back using it again. I am now using the code for my background image which will rotate when you enter a new gallery. I’m so proud of myself, learned so much without needing any help, but for the life of me I can’t get it to randomize. Here is the code:
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
description* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
}
id = setInterval(preloadPic, 100);
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("bkg.xml");
var p = 0;
var current;
var k = 0;
// ////////////////////////////////
function preloadPic() {
clearInterval(id);
var con = picture.duplicateMovieClip("con"+k, 9984+k);
con.loadMovie(image[p]);
preloader._visible = 1;
con._alpha = 0;
var temp = _root.createEmptyMovieClip("temp"+k, 99+k);
k++;
temp.onEnterFrame = function() {
var total = con.getBytesTotal();
var loaded = con.getBytesLoaded();
percent = Math.round(loaded/total*100);
preloader.preload_bar._xscale = percent;
if (con._width) {
con._x = 100;
con._y = 100;
if((Stage.width > 1600) || (Stage.height > 1200)) {
proportion = 1.33;
con._width = Stage.width;
con._height = Stage.height * proportion;
}else{
con._width = 1600;
con._height = 1200;
}
preloader._visible = 0;
con.onEnterFrame = fadeIn;
delete this.onEnterFrame;
}
};
}
MovieClip.prototype.fadeIn = function() {
if (this._alpha<100) {
current._alpha -= 4;
this._alpha += 4;
} else {
current._visible = 0;
current = this;
delete this.onEnterFrame;
}
};
function nextImage() {
p<total-1 ? (p++, preloadPic()) : null;
}
I have tried adding: p = Math.floor(Math.random() * total); and it *almost *works. It seems everytime the last node is called it stops working (also at other random times, haven’t found a pattern).
Heck, at this point, if someone can help me just loop this so after you hit the last node it starts back at the beginning I’d love it.
Thanks, can’t wait to show you guys all the stuff I’ve been doing! Couldn’t have done it without you all!