I am trying to create a random quote generator in Flash MX. I have built an XML file with a bunch of quotes, and currently, when the user clicks the “next” button, the application goes to the very next quote in the XML file. This is not “random” as I’d like it to be, and was wondering if anyone has any experience in randomizing data that is found in an XML file. Below is my actionscript:
quotes_xml = new XML();
quotes_xml.onLoad = startQuoteShow;
quotes_xml.load(“quotes.xml”);
quotes_xml.ignoreWhite = true;
//
// Show the first quote and intialize variables
function startQuoteShow(success) {
if (success == true) {
rootNode = quotes_xml.firstChild;
totalQuotes = rootNode.childNodes.length;
firstQuoteNode = rootNode.firstChild;
currentQuoteNode = firstQuoteNode;
currentIndex = 1;
updateQuote(firstQuoteNode);
}
}
//
// Updates the current slide with new image and text
function updateQuote(newQuoteNode) {
id = newQuoteNode.attributes.id;
author = newQuoteNode.attributes.author;
quoteText = newQuoteNode.firstChild.nodeValue;
//loadMovie(imagePath, targetClip);
}
//
// Event handler for ‘Next quote’ button
next_btn.onRelease = function() {
//nextQuoteNode = currentQuoteNode.nextSibling;
nextQuoteNode = random(currentQuoteNode.nextSibling);
trace (nextQuoteNode);
if (nextQuoteNode == null) {
break;
} else {
currentIndex++;
updateQuote(nextQuoteNode);
currentQuoteNode = nextQuoteNode;
}
};