关于flash好友列表的练习
2013-04-17 10:25
316 查看
package module.friendship { import com.greensock.TweenMax; import com.xinglong.dataManager.UserData; import flash.display.MovieClip; import flash.events.MouseEvent; import module.JModule; import module.JModuleConfig; import module.JTool; import module.ResourceFactory; import module.events.JModuleEvent; import module.friendship.cell.Friend_cell; public class Module_Friendship extends JModule{ public var _data:Array = new Array(); //装载从外部来的数据 public var listArr:Array = new Array(); //朋友数组 private var currentPage:int = 1; //当前页码 private var pageSize:int = 6; //每页显示六个好友 private var totalPage:int = 30; //所有页数 private var filter:Object; /** * @param data 好友数据 */ public function Module_Friendship(data:Array) { trace("Module_Friendship"); //资源加载URL,默认为模块下swf/resource.swf,无需配置 ResourceFile=null; //模块唯一标识ID,与模块包名相同 moduleID="friendship"; //资源MC列表,键名与链接ID配对,多个用逗号分隔 MCList="mc:_mc"; //是否单例 isSingleton=true; //是否模式窗口 isModel=false; _data = data; super(); } /** * 初始化模板接口,子类覆盖继承作初始化 */ public override function init() { var uiClass:* = ResourceFactory.getModuleClass(moduleID, "_mc"); creatMC(uiClass, 904, 71); //隐藏 initUI(); initEvent(); } private function creatMC(mcCS:*, initX:int, initY:int) { this.mc = new mcCS(); this.mc.x = initX; this.mc.y = initY; this.addChild(this.mc); } /** * 设置列表数据,同时更新UI列表 */ // public function setData(d:*){ // _data = d; // pageControl(1); // } /** *设置过滤条件 ,同时更新UI列表 */ private function setFilter(f:Object){ filter = f; pageControl(1); } private function initUI() { this.setFilter({type:"好友"}); this.mc.btn_switch.gotoAndStop(2); } /** * 初始化监听器 */ private function initEvent() { this.mc.btn_switch.addEventListener(MouseEvent.CLICK,mouseClick); //展入展出按钮监听器 this.mc.btn_friend.addEventListener(MouseEvent.CLICK,mouseClick);//好友监听器 this.mc.btn_adversary.addEventListener(MouseEvent.CLICK,mouseClick);//仇人 this.mc.left_btn.addEventListener(MouseEvent.CLICK,mouseClick);//左边按钮 this.mc.right_btn.addEventListener(MouseEvent.CLICK,mouseClick);//右边按钮 } private function mouseClick(e:MouseEvent) { if (e.currentTarget.enabled) { switch (e.currentTarget.name) { case "btn_switch": switchType(); break; case "btn_friend": this.setFilter({type:"好友"}); // currentType = 0; break; case "btn_adversary": this.setFilter({type:"仇人"}); // currentType = 1; break; case "left_btn": if(currentPage > 1){ currentPage--; pageControl(currentPage); } break; case "right_btn": if(currentPage < totalPage){ currentPage ++ ; pageControl(currentPage); } break; } } } /** * @return * 面板收起或展开 */ private function switchType(){ //判断面板是否展开 if(this.mc.btn_switch.currentFrame == 1){ hide(); this.mc.btn_switch.gotoAndStop(2); trace("bt hide"); } else if(this.mc.btn_switch.currentFrame == 2){ show(); this.mc.btn_switch.gotoAndStop(1); trace("bt open"); } } /** * @param pageNum 页数 * 分页 */ private function pageControl(pageNum:Number) { for(var i:uint = 0;i < listArr.length ; i++){ listArr[i].remove(); listArr[i].removeEventListener(MouseEvent.MOUSE_DOWN,selectItem); } listArr = []; var counter:uint = 0; //获得同种类型列表的长度 for(var i=0;i<_data.length;i++){ //判断是否符合过滤条件 if(_data[i] && JTool.meet(_data[i],filter)) { var cell:Friend_cell = new Friend_cell(_data[i]); listArr.push(cell); } } //全部页数 listArr.length % pageSize < pageSize ? totalPage =listArr.length / pageSize + 1:totalPage =listArr.length / pageSize; //判断当前页数 if(pageNum > totalPage && pageNum<1){ currentPage = 1; } else if(pageNum < totalPage){ currentPage = pageNum; } //求取每页的数据条数,再进行分页添加 var num:uint = listArr.length - currentPage * pageSize > 0 ? pageSize: pageSize - (currentPage * pageSize - listArr.length); for(var i:uint = 0;i < num ; i++){ if(listArr[i]!=null){ listArr[i].x = 0 ; listArr[i].y = counter * listArr[i].height + 10; mc.loadMc.addChild(listArr[i]); listArr[i].addEventListener(MouseEvent.MOUSE_DOWN,selectItem); listArr[i].mouseChildren = false; listArr[i].mouseEnabled = true; listArr[i].buttonMode = true; counter ++ ; } } mc.page_txt.text = currentPage +"/"+totalPage; } /** * 派发点击单个好友选项的事件 */ private function selectItem(e:MouseEvent){ var cell:Friend_cell = e.currentTarget as Friend_cell ; this.dispatchEvent(new JModuleEvent(JModuleEvent.ITEM_SELECTED,cell.itemObj)); trace("cell click"); } //显示效果 public function show() { TweenMax.to(mc, 0.3, {bezierThrough:[{x:715, y:71}]}); } //隐藏效果 public function hide() { TweenMax.to(mc, 0.3, {bezierThrough:[{x:904, y:71}]}); } public override function handleRemove() { this.mc.btn_switch.removeEventListener(MouseEvent.CLICK,mouseClick); this.mc.btn_friend.removeEventListener(MouseEvent.CLICK,mouseClick); this.mc.btn_adversary.removeEventListener(MouseEvent.CLICK,mouseClick); this.mc.left_btn.removeEventListener(MouseEvent.CLICK,mouseClick); this.mc.right_btn.removeEventListener(MouseEvent.CLICK,mouseClick); } } }
相关文章推荐
- Python小练习-自动登录人人发送消息并返回好友列表
- [python]学习笔记4-关于列表去重练习
- PHP语言 -- 数据访问练习(好友列表)
- jQuery练习一好友列表变色
- HTMO DOM部分---小练习;列表之间移动、日期选择、好友选中、滑动效果、滚动条效果、飞入飞出效果。
- XMPP客户端关于用户组和好友列表的管理的一个实现方法
- Winform:关于IM好友列表
- 练习:QQ 好友列表
- XMPP客户端关于用户组和好友列表的管理的一个实现方法
- SQL语句练习实例之五 WMS系统中的关于LIFO或FIFO的问题分析
- [翻译练习]关于在传统ASP.NET Web应用程序上面使用Routing的一些笔记
- PHP 获取MSN好友列表的代码(2009-05-14测试通过)
- 关于python的基础知识17 -- 列表、数组和矩阵
- android:listview实现qq,微信好友列表(头像,昵称,个性签名)
- 关于下拉框列表不可选择相同值的设置一:当前下拉框不可选
- 关于DataGrid列表样式
- 关于.NET Framework 一些哈希加密类的练习
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)
- 关于用户管理的练习
- JcomboBox下拉列表练习