-
Code help
I purchased this following code and it works swell to display random quotes. However, now the client doesn't want them to be random. Can anyone help me tweak it? Assuming that it is simple...?
Code:
///// CUSTOM \\\\\
rqXMLFile = "quotes.xml"; //The XML file
rqFPS = 31; //Framerate of this .fla
///// XML \\\\\
rqXML = new XML(); //Create new XML variable
rqXML.ignoreWhite = true; //Ignore the white spaces in the XML file
rqXML.onLoad = function(succes){ //Function for when the XML is loaded
if(succes){ //If the file is succesfully loaded
rqTotal = rqXML.firstChild.childNodes[0].childNodes.length; //Total amount of quotes
rqDelay = Number(rqXML.firstChild.childNodes[0].attributes.delay)*rqFPS; //The delay between each quote
rqFadeSpeed = Number(rqXML.firstChild.childNodes[0].attributes.fadespeed); //The speed in which the quotes fade in and out
rqQuote = new Array(); //Array for the quotes
rqAuthor = new Array(); //Array for the authors
for(i=0;i<rqTotal;i++){ //Go through every quote to get the info that is needed
rqQuote[i] = rqXML.firstChild.childNodes[0].childNodes[i].childNodes[0].firstChild.toString(); //Get the quote, store it in the array
rqAuthor[i] = rqXML.firstChild.childNodes[0].childNodes[i].childNodes[1].firstChild.toString(); //Get the author, store it in the array
}
quoteText._alpha = 0; //Set the textfield's alpha to 0, so you cant see it yet
authorText._alpha = 0;//Set the textfield's alpha to 0, so you cant see it yet
selectQuote(); //Select the first quote to start off with
}else{ //If the XML file is not loaded succesfully, give error
quoteText.text = "Error opening XML file"; //The error to be displayed
}
}
rqXML.load(rqXMLFile); //Load this XML file
///// NEXY QUOTE \\\\\
function nextQuote(){ //Function to load the next Quote
this.onEnterFrame = function(){ //Create a function that repeats itself every FPS
quoteText._alpha -= rqFadeSpeed; //Fade out the quoteText
authorText._alpha -= rqFadeSpeed;//Fade out the authorText
if(quoteText._alpha <= 0){ //When quoteText and authorText are faded out
quoteText._alpha = 0; //Set quoteText to fixed 0 alpha
authorText._alpha = 0; //Set authorText to fixed 0 alpha
delete this.onEnterFrame; //Remove this function, so it stops repeating itself for no reason
selectQuote(); //Select the next quote
}
}
}
///// SELECT QUOTE \\\\\
rqDone = new Array(); //An array to store every quote in that has already been used
function selectQuote(){ //Function for selecting the next quote and author
//First, check if the array is not full yet
rqIndex = 0; //Index to see how many quotes have been used
for(i=0;i<rqTotal;i++){ //Go through all quotes
if(rqDone[i] == true){ //If this quote has already been used
rqIndex++; //Add one to the index
}
}
if(rqIndex == rqTotal){ //If all quotes are used
rqDone = new Array(); //Start over by resetting the array
}
//Now, select a random number
rqNum = random(rqTotal); //Select any number in the total amount of quotes
while(rqDone[rqNum] == true){ //Repeat the next line as long as the quote has already been used
rqNum = random(rqTotal); //Select a new number to check if its used or not
}
//If it has found a number that has not been used, show the quote
rqDone[rqNum] = true; //Set the newly selected quote number into the array, because it is being used now
showQuote(rqNum); //Show the selected quote
}
///// SHOW QUOTE \\\\\
function showQuote(rqNum:Number){ //Function which shows the selected quote
numText.text = rqNum +"/"+ rqTotal; //Set the number of the quote into the textfield
quoteText.htmlText = rqQuote[rqNum]; //Set the quote into the textfield
quoteText.htmlText = quoteText.text; //This extra line makes sure the HTML works correctly (because of the CDATA tags)
authorText.htmlText = rqAuthor[rqNum]; //Set the author in the textfield
authorText.htmlText = "<b>-</b> "+authorText.text; //This extra line makes sure the HTML works correctly (because of the CDATA tags)
this.onEnterFrame = function(){ //Create a function that repeats itself every FPS
quoteText._alpha += rqFadeSpeed; //Fade in the quoteText
authorText._alpha += rqFadeSpeed; //Fade in the authorText
if(quoteText._alpha >= 100){ //When the quoteText and authorText are faded in
quoteText._alpha = 100; //Set quoteText to fixed 100 alpha
authorText._alpha = 100;//Set authorText to fixed 100 alpha
delete this.onEnterFrame; //Remove this function, so it stops repeating itself for no reason
}
}
}
///// TIMER \\\\\
rqTimerCount = 0; //Set the timer count to 0 to start off with
this.createEmptyMovieClip("rqTimer",this.getNextHighestDepth()); //Create an empty movieclip, which will act as the timer
rqTimer.onEnterFrame = function(){ //Create a function that repeats itself every FPS
rqTimerCount++; //Add one to the timer count
if(rqTimerCount >= rqDelay){ //If the timer count is higher than, or equal to the selected delay
rqTimerCount = 0; //Reset the timer count
nextQuote(); //Select the next quote
}
}
-
Need to see the selectQuote function code.
-
Thanks! The code above and the xml below is everything:
Code:
<xml>
<quotes delay="10" fadespeed="5">
<quote>
<quote><![CDATA[<b>Friendship is like peeing on yourself: everyone can see it, but only you get the warm feeling that it brings.</b>]]></quote>
<author><![CDATA[<b>Unknown Author</b>]]></author>
</quote>
<quote>
<quote><![CDATA[<b>The man who smiles when things go wrong has thought of someone to blame it on.</b>]]></quote>
<author><![CDATA[<b>Robert Bloch</b>]]></author>
</quote>
ATA[<b>Unknown Author</b>]]></author>
</quote>
</quotes>
</xml>
-
This is calling the selectQuote function.
You may have to search a bit, but somewhere is the code for the actual function.
-
It's not this?:
Code:
///// SELECT QUOTE \\\\\
rqDone = new Array(); //An array to store every quote in that has already been used
function selectQuote(){ //Function for selecting the next quote and author
//First, check if the array is not full yet
rqIndex = 0; //Index to see how many quotes have been used
for(i=0;i<rqTotal;i++){ //Go through all quotes
if(rqDone[i] == true){ //If this quote has already been used
rqIndex++; //Add one to the index
}
}
if(rqIndex == rqTotal){ //If all quotes are used
rqDone = new Array(); //Start over by resetting the array
}
//Now, select a random number
rqNum = random(rqTotal); //Select any number in the total amount of quotes
while(rqDone[rqNum] == true){ //Repeat the next line as long as the quote has already been used
rqNum = random(rqTotal); //Select a new number to check if its used or not
}
//If it has found a number that has not been used, show the quote
rqDone[rqNum] = true; //Set the newly selected quote number into the array, because it is being used now
showQuote(rqNum); //Show the selected quote
}
-
Sorry, must be over tired, I didn't see it in the first post .
Change the first call as shown below...
Code:
rqXML.onLoad = function(succes){ //Function for when the XML is loaded
if(succes){ //If the file is succesfully loaded
rqTotal = rqXML.firstChild.childNodes[0].childNodes.length; //Total amount of quotes
rqDelay = Number(rqXML.firstChild.childNodes[0].attributes.delay)*rqFPS; //The delay between each quote
rqFadeSpeed = Number(rqXML.firstChild.childNodes[0].attributes.fadespeed); //The speed in which the quotes fade in and out
rqQuote = new Array(); //Array for the quotes
rqAuthor = new Array(); //Array for the authors
for(i=0;i<rqTotal;i++){ //Go through every quote to get the info that is needed
rqQuote[i] = rqXML.firstChild.childNodes[0].childNodes[i].childNodes[0].firstChild.toString(); //Get the quote, store it in the array
rqAuthor[i] = rqXML.firstChild.childNodes[0].childNodes[i].childNodes[1].firstChild.toString(); //Get the author, store it in the array
}
quoteText._alpha = 0; //Set the textfield's alpha to 0, so you cant see it yet
authorText._alpha = 0;//Set the textfield's alpha to 0, so you cant see it yet
selectQuote(true); //Select the first quote to start off with
Replace the existing function with this one...
Code:
function selectQuote(firstOne) {
if (firstOne == undefined) {
rqQuote.push(rqQuote.shift());
rqAuthor.push(rqAuthor.shift());
}
showQuote(0);
}
-
No need to apologize. I'm the one with his hand out. That worked beautifully! Thank you, thank you!
Last edited by sammymaudlin; 02-02-2009 at 07:51 PM.
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
|