Have you ever wanted your List items to automatically scroll…. well I have. I am building a Flex application that shows the latest 10 items in a list container.
I would like to cycle through the list once every 5 seconds, taking the last item and displaying it at the top. I am using AMFPHP to retrieve the content from a MySQL database.
So this is what I did
private function load():void
{
gateway = new RemotingConnection(serverName);
gateway.call(“mydetails”, new Responder(onResult, onFault));
}
private function onResult(result:Array):void
{
ac = new ArrayCollection()
for each(item in result){
var o:TicketVO = new TicketVO();
o.ticketId = item["ticketid"];
o.summary = item["summary"];
ac.addItem(o);
}
lRenderer.dataProvider = ac; // lRenderer is the name of my List container
timer = new Timer(5000, 0);
timer.addEventListener(TimerEvent.TIMER, updateList, false, 0, true);
timer.start();
}
private function updateList(event:TimerEvent):void
{
var len:Number = ac.length;
var i:Object = new Object();
i = lRenderer.dataProvider.getItemAt(len-1, 1); // Get the last item in the list
lRenderer.dataProvider.removeItemAt(len-1); // Remove the item from the list
lRenderer.dataProvider.addItemAt(i,0); // Add it to the top of the list
}
The above is just a snapshot of the code I used.
Hope that helps some.