I have borrowed the code from Tiago’s web blog.
http://blog.six4rty.ch/tutorials/flash-cs3-quote-rotator/
I have noticed a few odd things, and have tried to send off to Tiago himself but have not received any response. I am in dire need of getting this to work properly, and am asking for help from this community. I have a primitive understanding of this AS3 code, and apologize if this may be a noob question.
I need to fix a couple things, with this code.
The first thing i noticed is the code seems to call for the .php file before it can load, so at times it will generate a “undefined” for both the quote and author.
The second thing is, which may tie into the first, there seems to be the occasion where the code doesn’t load the php file at all. The author and quote will be blank for a duration.
And the third question i have is how do i get the text to fade out again after the fade in after an interval.
I would greatly appreciate any help with this, as I am finding very little in regards to others that may have noticed these issues and possible fix’s for it.
Thank you in advance.
PS. IF you wish to see the bug in action, keep hitting refresh on my page @ http://www.ramblerfabrication.com/test.html
import caurina.transitions.Tweener;
var quote:Array = new Array();
var author:Array = new Array();
var totalQuotes:Number;
var rotateTimer:Timer = new Timer(10000, 100); //rotates the quote every 2 seconds for 100 times
quoteMC.alpha = 0;
authMC.alpha = 0;
rotateTimer.addEventListener("timer", rotateQuote);//add a listener to the timer
rotateTimer.start(); // start the timer
function init():void {
var quotesXML:XML = new XML();
quotesXML.ignoreWhitespace = true;
var XMLURL:URLRequest = new URLRequest("http://www.ramblerfabrication.com/images/quoterotator/quotes1.xml");
var myLoader:URLLoader = new URLLoader(XMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void {
quotesXML = XML(myLoader.data);
totalQuotes = quotesXML.quote.length();
for (var i:int = 0; i < quotesXML.quote.length(); i++) {
quote* = quotesXML.quote*.text;
author* = quotesXML.quote*.author;
var initRandom:Number = randomNumber(0, totalQuotes);
quoteMC.quote_txt.text = String(quote[initRandom]);
authMC.author_txt.text = String(author[initRandom]);
}
}
}
function rotateQuote(evt:TimerEvent) {
quoteMC.quote_txt.text = "";
authMC.author_txt.text = "";
var randomness:Number = randomNumber(0, totalQuotes);
Tweener.addTween(quoteMC, {alpha:1, time:5});
Tweener.addTween(authMC, {alpha:1, time:5});
quoteMC.quote_txt.text = quote[randomness]||"";
authMC.author_txt.text = author[randomness]||"";
}
function randomNumber(low:Number, high:Number):Number {
var low:Number = low;
var high:Number = high;
quoteMC.alpha = 0;
authMC.alpha = 0;
Tweener.addTween(quoteMC, {alpha:1, time:5});
Tweener.addTween(authMC, {alpha:1, time:5});
return Math.round(Math.random() * high - low) + low;
}
init();