PaginationManager For photo Gallery creation

January 2nd, 2012 by aabhaanjan

images
[xml]

package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class PaginationManager extends MovieClip
{
/*
* @Comments : Before using this class you need to create a container MovieClip
* in your FLA with linkage ID ‘_mcContainer’. Inside the _mcContainer there should be ‘btnNext’ & ‘btnPrev’
*
* */

private var _pageCounter:int = 1;
private var _NoOfObjectAtOnce:int;
private var _objCounter:int = 0;
private var _totalPages:int
private var _objectArray:Array;
private var _PosX:int;
private var _PosY:int;

public function PaginationManager()
{
super();
}
/*
* @Params :
* @__array : Pass the array of those object which you want to show in the pagination.
* @__NoOfObjectAtOnce : This is the parameter for how many objects you want to show in one page.
* @__PosX : Starting X position.
* @__PosY : Starting Y position.
*
* */
public function init(__array:Array,__NoOfObjectAtOnce:int,__PosX:int,__PosY:int):void{
_objectArray = __array;
_noOfObjectAtOnce = __noOfObjectAtOnce;
_PosX = __PosX;
_PosY = __PosY;
_totalPages = Math.ceil(_objectArray.length/_noOfObjectAtOnce);
btnPrev.addEventListener(MouseEvent.CLICK, prevPage);
btnNext.addEventListener(MouseEvent.CLICK, nextPage);
generateNewPage();
}
/*
* @Params :Null
* @Comments : This function will genarate the pages/new thumbnails.
* */
private function generateNewPage():void{
for(var __i=(_pageCounter-1)*_noOfObjectAtOnce;__i<_pageCounter*_noOfObjectAtOnce;__i++){ if(__i < _objectArray.length){ addObjects(); } } _objCounter=0; } private function addObjects():void { var _newMCcontainer:_mcContainer = new _mcContainer(); _newMCcontainer.x = _PosX; _newMCcontainer.y = _PosY + _newMCcontainer.height *_objCounter; _newMCcontainer.name = 'container'+_objCounter; addChild(_newMCcontainer); _objCounter ++; } private function removeObjectArray():void{ for(i=0;i<_noOfObjectAtOnce;i++){ removeChild(getChildByName('container'+i)); } } /* * @Params :event * @Comments : On Clicking previous button this function will be called. * */ private function prevPage(event:MouseEvent):void{ if(_pageCounter > 1){
removePage();
_pageCounter –;
generateNewPage();
}
}
/*
* @Params :event
* @Comments : On Clicking next button this function will be called.
* */
private function nextPage(event:MouseEvent):void{
if(_pageCounter < _totalPages){ removePage(); _pageCounter ++; generateNewPage(); } } } } [/xml]