Okay, so I've been reading through all of this and I've attempted to alter a slideshow I'm working on to use setInterval. I use Flash MX btw.
I am creating a slideshow where I use two buttons to navigate between the images. The images load via xml and load into a movieclip called myImage then a movieclip called mc_fader plays over top of the image to reveal the image. mc_fader automatically resizes based on the width of the movie. I want have the "next" button set up so that when a user clicks on it, he or she sees a preloader in a text box called progress_txt that shows how much of the next image has loaded. When that image has loaded, I would like to show the image(myImage) with mc_fader overtop and cause mc_fader to play. But when I click on the "next" button, the progress_txt remains "Loading Complete". If I click the "next" button twice very quickly, it works. What gives?
to see an example click here
Code:slides_xml = new XML();
slides_xml.onLoad = startSlideShow;
slides_xml.load("fashion_slideshow.xml");
slides_xml.ignoreWhite = true;
//
// Show the first slide and intialize variables
function startSlideShow(success) {
if (success == true) {
rootNode = slides_xml.firstChild;
totalSlides = rootNode.childNodes.length;
firstSlideNode = rootNode.firstChild;
currentSlideNode = firstSlideNode;
currentIndex = 1;
updateSlide(firstSlideNode);
}else gotoAndStop(10);
}
//
// Updates the current slide with new image and text
function updateSlide(newSlideNode) {
fader = mc_fader;
imagePath = newSlideNode.attributes.jpegURL;
slideText = newSlideNode.firstChild.nodeValue;
loadMovie(imagePath, myImage);
}
checkImageLoadingStatus = function(){
progress_txt.text = "boogabooga";
// var total = 0 ;
var total = myImage.getBytesTotal();
if (isNaN(total) || total == 0){
progress_txt.text = "Loading...";
}else {
var loaded = myImage.getBytesLoaded();
if (total == loaded){
progress_txt.text = "Loading Complete";
mc_fader._width = myImage._width;
mc_fader.gotoAndPlay(1);
// mc_fader._visible = true;
clearInterval(loadingID);
}else{
progress_txt.text = Math.round(loaded/1024) +" kb of "+ Math.round(total/1024); // divide 1024 to get kilobytes
}
}
}
//
// Event handler for 'Next slide' button
next_btn.onRelease = function() {
progress_txt.text = "";
nextSlideNode = currentSlideNode.nextSibling;
if (nextSlideNode == null) {
break;
mc_endfade.gotoAndPlay(2);
} else {
clearInterval(loadingID); // clear any current interval that might be running
loadingID = setInterval(checkImageLoadingStatus, 50); // every 50 milliseconds
mc_endfade.gotoAndStop(1);
currentIndex++;
updateSlide(nextSlideNode);
currentSlideNode = nextSlideNode;
checkImageLoadingStatus();
}
};
//
// Event handler for 'Previous slide' button
back_btn.onRelease = function() {
// removeMovieClip.myImage;
// this._parent.createEmptyMovieClip("myImage",1);
// myImage._x = 87.5;
// myImage._y = 0;
previousSlideNode = currentSlideNode.previousSibling;
if (previousSlideNode == null) {
break;
mc_endfade.gotoAndPlay(2);
} else {
clearInterval(loadingID); // clear any current interval that might be running
loadingID = setInterval(checkImageLoadingStatus, 50); // every 50 milliseconds
checkImageLoadingStatus();
mc_endfade.gotoAndStop(1);
currentIndex--;
updateSlide(previousSlideNode);
currentSlideNode = previousSlideNode;
}
};
