I'm using this wonderful slide show code found somewhere on here, that fades images in and out very nicely. I have an empty movie clip called photo on the main stage, and a folder of jpgs both landscape and portrait. So far so good.
Code:
fscommand("allowscale", "false");
this.pathToPics = "images/";
// fill this array with your pics
this.pArray = ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg"];
this.fadeSpeed = 15;
//Was 20...
this.pIndex = 0;
// MovieClip methods ----------------------------------
// d=direction; should 1 or -1 but can be any number
//loads an image automatically when you run animation
_level0.autoPlay = true;
_level0.autoPlay = true;
trace("AUTOPLAY IS ON!");
setTimerCtrl();
// Picture will change in 5 seconds, as set in the setTimerCtrl() function.
loadMovie(this.pathToPics + this.pArray[0], _root.photo);
changePhoto = function(d)
{
// make sure pIndex falls within pArray.length
// this.pIndex = (this.pIndex+d)%this.pArray.length;
// if (this.pIndex<0) {
if ((this.pIndex + d) < (this.pArray.length - 1))
{
this.pIndex++;
}
else
{
this.pIndex = this.pArray.length - 1;
//MY ADDITION TO THE CODE TO END THE SLIDE SHOW AFTER THE LAST JPG
trace("AUTOPLAY IS OFF!");
_level0.autoPlay = false;
clearInterval(intervalID);
//Clear the interval created from the auto state.
}
trace("\tthis.pIndex = " + this.pIndex);
this.onEnterFrame = fadeOut;
};
fadeOut = function()
{
if (this.photo._alpha > this.fadeSpeed)
{
this.photo._alpha -= this.fadeSpeed;
}
else
{
this.loadPhoto();
}
};
loadPhoto = function()
{
// specify the movieclip to load images into
var p = _root.photo;
//------------------------------------------
p._alpha = 0;
trace("this.pIndex = " + this.pIndex);
trace("this.pArray = " + this.pArray);
trace("this.pArray[this.pIndex] = " + this.pArray[this.pIndex]);
trace("this.pathToPics+this.pArray[this.pIndex] = " + (this.pathToPics + this.pArray[this.pIndex]));
p.loadMovie(this.pathToPics + this.pArray[this.pIndex]);
this.onEnterFrame = loadMeter;
};
loadMeter = function()
{
var i, l, t;
l = this.photo.getBytesLoaded();
t = this.photo.getBytesTotal();
if (t > 4 && t == l)
{
this.onEnterFrame = fadeIn;
}
else
{
trace(l / t);
}
};
fadeIn = function()
{
if (this.photo._alpha < 100 - this.fadeSpeed)
{
this.photo._alpha += this.fadeSpeed;
}
else
{
this.photo._alpha = 100;
this.onEnterFrame = null;
}
};
// Actions that should advance the slide show one image. See script on button for more script.
/* MY ADDITION AND CHANGE */
function setTimerCtrl()
{
autoTimer = 5000;
//5 seconds between pictures... Number of seconds * 1000...
clearInterval(intervalID);
//Clear the interval for auto slide
intervalID = setInterval(autoSlide, autoTimer);
//Set an interval for auto slide
}
function autoSlide()
{
_root.changePhoto(1);
}
I've searched and tried for two days to figure out what to modify to have the images appear centered, as they are both portrait and landscape jpgs. If I add centering code to the "photo" movieclip itself with an onClipEvent, it's ignored. If I add it to the code above it either crops the image or ignores it.
I understand the concept of the image needing to load before the height and width is available, and assigning the value of half the height and half the width to the x and y position of the clip. I'm just not sure where to add this kind of code to make it work with the auto-loading slide show.
Any help/hints are hugely appreciated.