-
[F8] script help random slideshow
I am a relative newbie. I have an autoplay random image xml slideshow. The problem is, I don't want the images to repeat until all of them have been shown. I've see posts with some hints about this, something about "shuffle" but I don't know what script or where I should add or change it. Any direction would be greatly appreciated!!!!
Here's the script:
//: SETUP INITIAL VARIABLES
var oldVar = 0; // keep track of previous random number
var newVar = 0; // used to load the next image
var si = 0; // interval variable
//: GET XML
var my_xml = new XML(); // create our xml object
my_xml.ignoreWhite = true; // tell object to ignore all the white space in the file
my_xml.onLoad = function (success) { // when load function is called, pass a temp variable
if (success) { // if the temp variable was passed; file was loaded
// now that the xml has loaded successfully
// lets setup our final variables
library = this.firstChild.childNodes; // get all the <jpg> nodes
maxVal = library.length; // max number of fotos
// now that we've retrieve our xml ...
delete my_xml; // delete our xml object
getImage(); // load first image
} else { // if the temp variable was not passed; file was not loaded
desc_txt.text = 'Error: XML Not Loaded'; // display an errorr message on your text field
}
}
my_xml.load('library.xml');
//: LOAD THE NEXT IAMGE
function getImage() {
newVar = Math.floor(Math.random() * maxVal); // get random number
if (newVar == oldVar) { // if number = old number..
getImage(); // get a number
} else { // else
oldVar = newVar; // set old to new number
container_mc.loadMovie (library[newVar].firstChild.firstChild.nodeValue); // load the next image
container_mc._alpha = 0; // set its alpha to 0
this.onEnterFrame = function () { // create loop
if (container_mc._width > 0) { // check that the image has been loaded
container_mc._x = Stage.width / 2 - container_mc._width / 2; // center movieclips to stage
container_mc._y = Stage.height / 2 - container_mc._height / 2; // center movieclip to stage
container_mc.onEnterFrame = fadeIn; // start fading out
desc_txt.text = library[newVar].firstChild.nextSibling.firstChild.nodeValue; // display the images description
delete this.onEnterFrame; // delete loop
}
}
}
}
//: FADE IN THE CURRENT MOVIECLIP
function fadeIn () {
if (this._alpha <= 100) { // if the movieclips alpha is greater than 0
this._alpha += 5; // reduce alpha by 5
} else { // else
this._alpha = 100; // reduce alpha to 0
delete this.onEnterFrame; // delete handler
si = setInterval(fadeOut, 2000); // after 2 seconds, fade out the movieclip
}
}
//: FADE OUT THE CURRENT MOVIECLIP
function fadeOut () {
clearInterval(si); // clear the interval variable
container_mc.onEnterFrame = function() { // create loop to fade out
if (this._alpha >= 0) { // if the movieclips alpha is greater than 0
this._alpha -= 5; // reduce alpha by 5
} else { // else
this._alpha = 0; // reduce alpha to 0
delete this.onEnterFrame; // delete handler
getImage(); // load the next image
}
}
}
Thanks again!
-
Array.prototype.shuffle = function() {
var myArray = new Array();
for (i=0; i<this.length; i++) {
var control = true;
while (control) {
j = int(random(this.length));
if (myArray[j] == undefined) {
myArray[j] = this[i];
control = false;
}
}
}
return myArray;
};
library = this.firstChild.childNodes; // get all the <jpg> nodes
randomLibrary = library.shuffle();
That should work
-
Where do I put the code?
Thanks for the quick response!! I'm really going to reveal my ignorance now...
Where in my script do I put the code you supplied?
Again, thanks so much for your help
-
the prototype goes somewhere at the top and just put in the shuffle right after you make the array
/: GET XML
var my_xml = new XML(); // create our xml object
my_xml.ignoreWhite = true; // tell object to ignore all the white space in the file
my_xml.onLoad = function (success) { // when load function is called, pass a temp variable
if (success) { // if the temp variable was passed; file was loaded
// now that the xml has loaded successfully
// lets setup our final variables
library = this.firstChild.childNodes; // get all the <jpg> nodes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|