<?xml version="1.0" encoding="utf-8"?> <mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" > <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.events.ItemClickEvent; import flash.events.KeyboardEvent; import mx.controls.DataGrid; import mx.validators.NumberValidator; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.controls.Alert; [Bindable] [Embed(source='assets/monitor/a4.png')] public var firstIcon:Class; public var firstPage:uint; [Bindable] [Embed(source='assets/monitor/a4.png')] public var preIcon:Class; public var prePage:uint; [Bindable] [Embed(source='assets/monitor/a4.png')] public var nextIcon:Class; public var nextPage:uint; [Bindable] [Embed(source='assets/monitor/a4.png')] public var lastIcon:Class; public var lastPage:uint; [Bindable]public var pageSize:int=15;//单页行数 [Bindable]public var totalPage:int=1;//总页数 [Bindable]public var currentPage:int=1;//当前页 [Bindable]public var totalClum:int=0;//总记录数 //分页函数 public var localFunction:Function=null; //重新为当前页的变量赋值 public function loadData(pageNum:int):void{ this.pageSize = setPageSize.selectedItem.data as Number; this.totalPage =Math.ceil(this.totalClum/this.pageSize); if(pageNum>0 && pageNum<=this.totalPage){ this.currentPage=pageNum; if(this.localFunction!=null){ localFunction(pageNum); }else{ Alert.show("请设置回调方法!"); } } } //重新设置每页显示记录数 public function changePagesize():void{ //当前页首条记录的序号 var currentPageRows:int=((this.currentPage-1)*this.pageSize); //Alert.show(String(currentPageRows)); //重新设置以后,单页显示记录数 this.pageSize = setPageSize.selectedItem.data as Number; //重新设置以后,总页数 this.totalPage =Math.ceil(this.totalClum/this.pageSize); //重新调整当前页码 //Alert.show(String(newPageNum)); if(this.localFunction!=null){ localFunction(this.currentPage); }else{ Alert.show("请设置回调方法!"); } } ]]> </fx:Script> <mx:Text id="temp" text="" visible="false" includeInLayout="false"/> <mx:HBox verticalGap="0" horizontalGap="0" horizontalAlign="center" verticalAlign="middle" > <mx:Text text="{' 共'+(totalClum)+'条记录'}" fontSize="12"/> <mx:Label text="每页显示:"/> <mx:ComboBox id="setPageSize" width="52" height="16" change="changePagesize()"> <mx:dataProvider> <fx:Array> <fx:Object label="15" data="15" /> <fx:Object label="20" data="20" /> <fx:Object label="30" data="30" /> <fx:Object label="40" data="40" /> <fx:Object label="50" data="50" /> <fx:Object label="60" data="60" /> <fx:Object label="70" data="70" /> <fx:Object label="80" data="80" /> </fx:Array> </mx:dataProvider> </mx:ComboBox> <mx:Label text="条"/> <mx:Button id="firstNavBtn" icon="{firstIcon}" width="10" height="10" click="loadData(1)" enabled="{lbtnPrevIoUs.enabled}"/> <mx:LinkButton id="lbtnFirst" label="首页" click="loadData(1)" enabled="{lbtnPrevIoUs.enabled}" fontSize="12"/> <mx:Button id="preNavBtn" icon="{preIcon}" width="7" height="10" click="loadData(currentPage-1)" enabled="{currentPage!=1?true:false}"/> <mx:LinkButton id="lbtnPrevIoUs" label="上一页" click="loadData(currentPage-1)" enabled="{currentPage!=1?true:false}" fontSize="12"/> <mx:Text text="{'【 '+(Math.ceil(this.totalClum/this.pageSize)>0?(currentPage):1)+'/'+(Math.ceil(this.totalClum/this.pageSize)>0?Math.ceil(this.totalClum/this.pageSize):1)+'页】 '}" fontSize="12"/> <mx:Button id="nextNavBtn" icon="{nextIcon}" width="7" height="10" click="loadData(currentPage+1)" enabled="{Math.ceil(this.totalClum/this.pageSize)>(currentPage)?true:false}"/> <mx:LinkButton id="lbtnNext" label="下一页" click="loadData(currentPage+1)" enabled="{Math.ceil(this.totalClum/this.pageSize)>(currentPage)?true:false}" fontSize="12"/> <mx:Button id="lastNavBtn" icon="{lastIcon}" width="10" height="10" click="loadData(Math.ceil(this.totalClum/this.pageSize))" enabled="{lbtnNext.enabled}"/> <mx:LinkButton id="lbtnLast" label="尾页" click="loadData(Math.ceil(this.totalClum/this.pageSize))" enabled="{lbtnNext.enabled}" fontSize="12"/> <mx:Label text="跳转到"/> <mx:NumericStepper id="nsPageNum" width="50" height="22" stepSize="1" minimum="1" maximum="{Math.ceil(this.totalClum/this.pageSize)}" enabled="{lbtnJump.enabled}" cornerRadius="0" fontSize="12"/> <mx:Label text="页"/> <mx:LinkButton id="lbtnJump" label="GO" click="loadData(nsPageNum.value)" enabled="{Math.ceil(this.totalClum/this.pageSize)>1?true:false}" fontSize="12"/> </mx:HBox> </mx:HBox>
2,在其他应用程序引用该组建
xmlns:common="com.primeton.common.*" 〉
3.使用组建
<common:PagingBar width="100%" height="5%" id="pageBar"/>
4.组建提供使用函数localFunction
protected function test_clickHandler():void { firstStart=0; pageSize=pageBar.pageSize; pageBar.localFunction=fun; } public function fun(pageNo:int):void { this.firstStart=(pageNo - 1) * pageBar.pageSize; pageSize=pageBar.pageSize; remote.destination = "service"; //remote.endpoint="messagebroker/amf"; //调用J2EE端类中的方法 remote.getFenYeXmls(firstStart,pageSize); //监听调用成功事件 remote.addEventListener(ResultEvent.RESULT,lineresult); //监听失败事件 remote.addEventListener(FaultEvent.FAULT,linefault); }ok