I have a news rotator that is populated from an RSS feed. The rotator has a timer that cycles through the news items, displaying a link and image and title for each item. I have the put in three buttons for the user to control the item that is displaying. A pause, forward and backward button.
My issue is that I’m not sure how to implement the button without messing up my timer that is already running. I was able to do the Pause button, which was simply to stop the timer. The forward and backward buttons are a bit more tricky. Any ideas?
This is what I have so far. Note that I have much of the code duplicated because I needed to initialize the objects for the first timer index. After the first item, the code runs from the timerHandler() function.
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("RSS.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
xmlLoader.removeEventListener(Event.COMPLETE, LoadXML);
ParseNews(xmlData);
}
function ParseNews(newsInput:XML):void{
var NumItems:int = newsInput.*.item.length();
var i:int=0;
var xmlItem = newsInput.channel.item*;
var NewsBox:MovieClip = new NewsItem();
var ImageLoader:Loader;
var dstring:String = xmlItem.pubDate;
/// split the array on spaces:
var ar:Array = dstring.split(" ");
var parsedDate:String = ar[2]+" "+ar[1];
addChild(NewsBox);
NewsBox.organization.htmlText = xmlItem.organization;
NewsBox.title.htmlText = "<b>"+xmlItem.title+"</b>";
NewsBox.description.addEventListener(TextEvent.LINK, textFieldLinkHandler);
NewsBox.description.htmlText = "<b>"+parsedDate+" - </b>"+xmlItem.description.toString()+"<a href='event:"+xmlItem.link+"'> <b><font color='#ecb510'> More>> </font></b></a>";
NewsBox.itemCount.htmlText = (i+1) + " of " + NumItems;
NewsBox.x = 200;
NewsBox.y = 60;
var url:String = xmlItem.image;
var urlRequest:URLRequest = new URLRequest(url);
ImageLoader = new Loader();
ImageLoader.load(urlRequest);
var imageIn:Tween = new Tween(ImageLoader, "alpha", Strong.easeInOut, 0, 1, .5, true);
addChild(ImageLoader);
ImageLoader.x = 10;
ImageLoader.y = 30;
if (i < 3)
{i++;}
else {i=0;}
var itemTimer:Timer = new Timer(7000);
itemTimer.addEventListener(TimerEvent.TIMER, timerHandler);
itemTimer.start();
pause.addEventListener(MouseEvent.CLICK, stopTimer);
right.addEventListener(MouseEvent.CLICK, Forward);
left.addEventListener(MouseEvent.CLICK, Backward);
function timerHandler(e:TimerEvent):void
{
removeChild(ImageLoader);
xmlItem = newsInput.channel.item*;
dstring = xmlItem.pubDate;
ar = dstring.split(" ");
parsedDate = ar[2]+" "+ar[1];
NewsBox.organization.htmlText = xmlItem.organization;
NewsBox.title.htmlText = "<b>"+xmlItem.title+"</b>";
NewsBox.description.addEventListener(TextEvent.LINK, textFieldLinkHandler);
NewsBox.description.htmlText = "<b>"+parsedDate+" - </b>"+xmlItem.description.toString()+"<a href='event:"+xmlItem.link+"'><b><font color='#ecb510'> More>> </font></b></a>";
NewsBox.itemCount.htmlText = (i+1) + " of " + NumItems;
var url:String = xmlItem.image;
var urlRequest:URLRequest = new URLRequest(url);
ImageLoader = new Loader();
ImageLoader.load(urlRequest);
var imageIn:Tween = new Tween(ImageLoader, "alpha", Strong.easeInOut, 0, 1, .5, true);
addChild(ImageLoader);
ImageLoader.x = 10;
ImageLoader.y = 30;
if (i < 3)
{i++;}
else {i=0;}
}
function textFieldLinkHandler(e:TextEvent):void
{
var passed:String = String(e.text);
trace(passed);
navigateToURL(new URLRequest(passed), "_blank");
}
function stopTimer(e:MouseEvent)
{
itemTimer.stop();
}
function Forward(e:MouseEvent)
{
//need code here to control timer and items
}
function Backward(e:MouseEvent)
{
//need code here to control timer and items
}
}
Thanks for any help