[AS3]as3分页代码示例:分页后自动居中写法示例
[AS3]as3分页代码示例:分页后自动居中写法示例
[AS3]as3分页代码示例:分页后自动居中写法示例
- package myapp.view
- {
- import flash.display.Loader;
- import flash.events.MouseEvent;
- import flash.net.URLRequest;
- import myapp.model.RoomProxy;
- import org.puremvc.as3.interfaces.IMediator;
- import org.puremvc.as3.patterns.mediator.Mediator;
- public class ActorListMediator extends Mediator implements IMediator
- {
- static public const NAME:String = "ActorListMediator";
- private var _al:actorList;
- private var _od:int = 0;
- private var _allArray:Array;
- private var _sa:actorCell;
- public var _goHall:Boolean = false;
- public function ActorListMediator(obj:Object=null)
- {
- super(NAME, obj);
- _al.x=6;
- _al.y=138;
- initPageBtn();
- main.addChild(_al);
- }
- /**
- * CuPlayer.com改变页数的方法
- * ---------------------------↓ 总页数-------↓ 当前页数
- **/
- private function doChangePage(pageCount:int,nowPage:int):void{
- //间距 27
- if(pageCount == nowPage){
- _al.btnDown.visible = false;
- _al.btnUp.visible = true;
- }
- if(nowPage == 1){
- _al.btnDown.visible = true;
- _al.btnUp.visible = false;
- }
- if(pageCount == 1){
- _al.btnDown.visible = false;
- _al.btnUp.visible = false;
- }
- for(var i:uint = 1;i<11;i++){
- if(i<=pageCount){
- _al["btn"+i+""].visible = true;
- }
- _al["btn"+i+""].txt.text = i;
- _al["btn"+i+""].addEventListener(MouseEvent.CLICK,pageBtnClick);
- }
- _al.btnUp.addEventListener(MouseEvent.CLICK,pageBtnClick);
- _al.btnDown.addEventListener(MouseEvent.CLICK,pageBtnClick);
- _al_al.btnMask.x = _al["btn"+nowPage+""].x;
- _al_al.btnMask.txt.text = _al["btn"+nowPage+""].txt.text;
- }
- public function get getMain():Main{
- return viewComponent as Main;
- }
- private function initPageBtn():void{
- for(var i:uint = 1;i<11;i++){
- _al["btn"+i+""].visible = false;
- }
- _al.btnDown.txt.text = "下一页";
- }
- private function pageBtnClick(e:MouseEvent):void{
- switch(e.target.txt.text){
- case "1":_al.btnUp.visible = false;
- _al.btnDown.visible = true;break;
- //case Math.ceil(_allArray.length/12)+"":_al.btnUp.visible = true;
- case "20":_al.btnUp.visible = true;
- _al.btnDown.visible = false;break;
- default :
- //不是第一个,也不是最后一个,中间的情况,如果点击第6个,位移←,
- btnMove(e.target.txt.text,e.target.name);
- }
- }
- /**
- * 根据按钮名字所判断执行的操作
- * ---------------------↓ 页数------↓ 被点中的按钮名称
- **/
- private function btnMove(txt:String,name:String):void{
- switch(name){
- case "btn1":doMove(4,false,parseInt(txt));break;
- case "btn2":doMove(3,false,parseInt(txt));break;
- case "btn3":doMove(2,false,parseInt(txt));break;
- case "btn4":doMove(1,false,parseInt(txt));break;
- case "btn5":if(Math.ceil(_allArray.length/12)==5){
- _al.btnUp.visible = true;
- _al.btnDown.visible = false;
- }else{
- _al.btnUp.visible = true;
- }break;
- case "btn6":doMove(1,true,parseInt(txt));break;
- case "btn7":doMove(2,true,parseInt(txt));break;
- case "btn8":doMove(3,true,parseInt(txt));break;
- case "btn9":doMove(4,true,parseInt(txt));break;
- case "btn10":doMove(5,true,parseInt(txt));break;
- case "btnUp":doMove(1,false,parseInt(txt),1);break;
- case "btnDown":doMove(1,true,parseInt(txt),2);break;
- }
- }
- /**
- * --------------------↓移动数量-------↓移动方向-----------
- * -------------------------------点中的页数--↓是否上页-1是,2下页,3其他↓
- **/
- private function doMove(moveTotal:int,direction:Boolean,txt:int,isUp:int=3):void{
- var temp:int;
- //上页可能出现没有第2页的问题,这个是中间变量!
- var tr:Boolean = false;
- if(isUp == 1){
- txt = parseInt(_al.btnMask.txt.text);
- txt--;
- tr = true;
- }
- if(isUp == 2){
- txt = parseInt(_al.btnMask.txt.text);
- txt++;
- }
- if(txt<=5 && _al.btn1.txt.text == "1"){
- if(txt == 1){
- _al.btnUp.visible = false;
- }else{
- _al.btnUp.visible = true;
- }
- for(var i2:int = 1;i2<=5;i2++){
- temp = parseInt(_al["btn"+i2].txt.text);
- if(temp == txt){
- _al_al.btnMask.x = _al["btn"+i2].x;
- _al_al.btnMask.txt.text = _al["btn"+i2].txt.text;
- }
- }
- return;
- }
- //if((txt+5) >= Math.ceil(_allArray.length/12) && parseInt(_al.btn10.txt.text) == Math.ceil(_allArray.length/12)){
- if((txt+5)>=(20) && _al.btn10.txt.text == "20"){
- //if(txt == Math.ceil(_allArray.length/12))
- if(txt == 20){
- _al.btnDown.visible = false;
- }else{
- _al.btnDown.visible = true;
- }
- for(var i3:int = 5;i3<=10;i3++){
- temp = parseInt(_al["btn"+i3].txt.text);
- if(temp == txt){
- _al_al.btnMask.x = _al["btn"+i3].x;
- _al_al.btnMask.txt.text = _al["btn"+i3].txt.text;
- }
- }
- return;
- }
- if(direction){
- //公式
- //moveTotal>Math.ceil(_allArray.length/12)?Math.ceil(_allArray.length/12)-
- moveTotal = parseInt(_al["btn10"].txt.text)+moveTotal>20?20-parseInt(_al["btn10"].txt.text):moveTotal;
- for(var i:int=1;i<11;i++){
- temp = parseInt(_al["btn"+i].txt.text)+moveTotal;
- _al["btn"+i].txt.text = temp+"";
- if(parseInt(_al["btn"+i].txt.text) == txt){
- _al_al.btnMask.x = _al["btn"+i].x;
- _al_al.btnMask.txt.text = _al["btn"+i].txt.text;
- }
- }
- _al.btnUp.visible = true;
- }else{
- //公式
- moveTotal = parseInt(_al["btn1"].txt.text)-moveTotal<0?moveTotal-(moveTotal-parseInt(_al["btn1"].txt.text)):moveTotal;
- for(var j:int=1;j<11;j++){
- if(tr){
- temp = parseInt(_al["btn"+j].txt.text)-moveTotal;
- }else{
- if(parseInt(_al["btn1"].txt.text)-moveTotal == 0){
- temp = parseInt(_al["btn"+j].txt.text)-moveTotal+1;
- }else{
- temp = parseInt(_al["btn"+j].txt.text)-moveTotal;
- try{
- if(temp == parseInt(_al["btn"+(j-1)].txt.text)){
- temp ++;
- }
- }catch(e:Error){}
- }
- }
- _al["btn"+j].txt.text = temp+"";
- if(parseInt(_al["btn"+j].txt.text) == txt){
- _al_al.btnMask.x = _al["btn"+j].x;
- _al_al.btnMask.txt.text = _al["btn"+j].txt.text;
- }
- }
- _al.btnDown.visible = true;
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...