-
[RESOLVED] help with no repeat from random xml load
I have a script I've been using on many sites that randomly loads an image from an xml file, and it works great. It loads an image, the image plays for 90 frames, goes back to frame one and repeats.
Now I'd like to enhance it so it doesn't repeat the last image, and I can't seem to get it to work. Any help would be great! Here's my original scritpt:
Code:
imgXML = new XML();
imgXML.ignoreWhite = true;
imgXML.onLoad = function(succes){
if (succes){
images = imgXML.firstChild.firstChild.childNodes;
imageIndex = Math.round(Math.random()*(images.length-1));
imageSRC = images[imageIndex].firstChild.nodeValue;
imageURL = images[imageIndex].attributes.url;
imageTARGET = images[imageIndex].attributes.target;
doMenu(this);
trace(imageSRC + " (" + imageURL + ")" + " (" + imageTARGET + ")");
}
}
imgXML.load("/images/top_banner/top_banner.xml");
function doMenu(xml:XML) {
empty_mc.loadMovie(imageSRC);
main_button.onRelease = function () {
getURL (imageURL, imageTARGET);
}
};
-
PHP Code:
while(imageIndex == oldindex){
imageIndex = Math.round(Math.random()*(images.length-1));
};
oldIndex = imageIndex;
-
Thanks for the reply moagrius, but I still can't seem to get it to work. Perhaps I'm not understanding where to drop the code in, I've tried putting it in the if statement, in the doMenu function, I've put it just about everywhere. Any extra help would really... well...help.
-
PHP Code:
var oldIndex = 0;
imgXML = new XML();
imgXML.ignoreWhite = true;
imgXML.onLoad = function(succes){
if (succes){
images = imgXML.firstChild.firstChild.childNodes;
imageIndex = Math.round(Math.random()*(images.length-1));
while(imageIndex == oldIndex){
imageIndex = Math.round(Math.random()*(images.length-1));
};
oldIndex = imageIndex;
imageSRC = images[imageIndex].firstChild.nodeValue;
imageURL = images[imageIndex].attributes.url;
imageTARGET = images[imageIndex].attributes.target;
doMenu(this);
trace(imageSRC + " (" + imageURL + ")" + " (" + imageTARGET + ")");
}
}
imgXML.load("/images/top_banner/top_banner.xml");
function doMenu(xml:XML) {
empty_mc.loadMovie(imageSRC);
main_button.onRelease = function () {
getURL (imageURL, imageTARGET);
}
};
-
Thanks for all your help moagrius! I got it working. I realize what my mistake was now - I had the code set up like that before, but my timeline was screwy.
When I wanted to load a new image, I realized that I only had to repass the imgXML.load and function doMenu code. Now it works great. Thanks!
-
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
|