Here’s some great code I pieced together using this forum. I would like to add Play/Pause functionality to it. Please have a look at the .fla :
Any suggestions/comments will be much appreciated!
delay = 6000;
p = 0;
// ///////////////////////////////////
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;
*/
}
// /*
firstImage();
} else {
content = "file not loaded!";
// */
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
// ///////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
}
};
Key.addListener(listen);
this.previous_btn.onRelease = function() {
prevImage();
};
this.next_btn.onRelease = function() {
nextImage();
};
// ///////////////////////////////////
spacing = 10;
containerMC._alpha = 0;
MovieClip.prototype.loadPic = function(pic) {
this._alpha = 0;
this.loadMovie(pic);
this._parent.onEnterFrame = function() {
var t = containerMC.getBytesTotal(), l = containerMC.getBytesLoaded();
bar._visible = 1;
per = Math.round((l/t)*100);
if (t != 0 && Math.round(l/t) == 1 && containerMC._width != 0) {
var w = containerMC._width+spacing, h = containerMC._height+spacing;
border.resizeMe(w,h);
bar._visible = 0;
frame._visible = 0;
loadText.text = "";
delete this.onEnterFrame;
} else {
bar._width = per;
//gives the bar a max width 100
loadText.text = per+" % loaded";
}
};
};
MovieClip.prototype.resizeMe = function(w, h) {
var speed = 3;
this.onEnterFrame = function() {
this._width += (w-this._width)/speed;
this._height += (h-this._height)/speed;
if (Math.abs(this._width-w)<1) {
this._width = w;
this._height = h;
containerMC._x = this._x-this._width/2+spacing/2;
containerMC._y = this._y-this._height/2+spacing/2;
containerMC._alpha += 5;
if (containerMC._alpha>90) {
containerMC._alpha = 100;
delete this.onEnterFrame;
}
}
};
};
// ///////////////////////////////////
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
/*
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
bar._visible = 1;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
bar._visible = 0;
if (picture._alpha<100) {
picture._alpha += 10;
}
}
};
*/
var myInterval;
function nextImage() {
p++;
p %= image.length;
//if (loaded == filesize) {
containerMC.loadPic(image[p], 1);
/*
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
*/
picture_num();
//trace(p);
this.selected_mc.gotoAndStop(p+2);
clearInterval(myInterval);
if (btn.playing) {
slideshow();
}
//}
}
function prevImage() {
clearInterval(myInterval);
if (btn.playing) {
slideshow();
}
if (p>0) {
p--;
} else {
p = image.length-1;
}
containerMC.loadPic(image[p], 1);
/*
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
*/
picture_num();
//trace(p);
this.selected_mc.gotoAndStop(p+2);
}
function firstImage() {
if (loaded == filesize) {
containerMC.loadPic(image[0], 1);
/*
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
*/
picture_num();
clearInterval(myInterval);
if (btn.playing) {
slideshow();
}
}
}
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+"/"+total;
}
function slideshow() {
myInterval = setInterval(pause_slideshow, delay);
function pause_slideshow() {
clearInterval(myInterval);
nextImage();
}
}
btn.t.text = "STOP";
btn.playing = true;
btn.onPress = function() {
if (this.playing) {
this.playing = false;
clearInterval(myInterval);
this.t.text = "PLAY";
} else {
this.playing = true;
nextImage();
this.t.text = "STOP";
}
};
// ///////////////////////////////////
//containerMC.loadPic("images/wed/wed1/1.jpg");