Pagination logic in short for viewing the images in a sequence
————————————————————————————–
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”initApp()”>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public var imageArray:Array;
public var length:Number;
public function initApp():void
{
imageArray=new Array();
imageArray.push("DSC01770.JPG");
imageArray.push("DSC01771.JPG");
imageArray.push("DSC01772.JPG");
imageArray.push("DSC01773.JPG");
imageArray.push("DSC01774.JPG");
imageArray.push("DSC01775.JPG");
imageArray.push("DSC01776.JPG");
img.source=imageArray[0];
length=imageArray.length;
}
public function showImage(event:MouseEvent):void
{
if(event.currentTarget.id==”next”)
{
for(var i:int=0;i<imageArray.length-1;i++)
{
if(img.source.toString()!= imageArray[length-1])
{
if(img.source.toString()==imageArray[i])
{
img.source=imageArray[i+1];
break;
}
}
else
{
Alert.show(“You viewing the last image”);
break;
}
}
}
else
{
for(var i:int=0;i<imageArray.length;i++)
{
if(img.source.toString()!= imageArray[0])
{
if(img.source.toString()==imageArray[i])
{
img.source=imageArray[i-1];
break;
}
}
else
{
Alert.show(“You viewing the first image”);
break;
}
}
}
}
]]>
</mx:Script>
<mx:Image id=”img” x=”43″ y=”35″ width=”238″ height=”227″>
</mx:Image>
<mx:Button id=”prev” x=”371″ y=”35″ label=”Previous” click=”showImage(event)” />
<mx:Button id=”next” x=”384″ y=”91″ label=”Next” click=”showImage(event)” />
</mx:Application>


