Wednesday, March 25, 2009

Flash Paginator: Get total of pages

Here is a really simple algorithm to get total of pages in a paginator.

var itemsTotal:int = 33;
var itemsPerPage:int = 6;

var remainder:int = itemsTotal % itemsPerPage;
var totalOfPages:Number = Math.round(itemsTotal / itemsPerPage);

if ( remainder > 0 )
{
totalOfPages = totalOfPages + 1;
}

trace(remainder + " = how many items are left.");
trace(totalOfPages + " = total of pages");

No comments: