class fj.page.JPage { public var _index:Number; //数目索引 public var _total:Number; //总的数目 public var _page:Number; //每页显示的条数 public function JPage(page, total) { _index = page; //一开始显示page页 _page = page; _total = total; } public function nextPage() { _index += _page; } public function prevPage() { _index -= _page; } public function firstPage() { _index = _page; } public function lastPage() { _index = _total; } //***得到和设置属性***// public function set index(index) { _index = index; } public function get index() { return _index; } public function set total(total) { _total = total; } public function get total() { return _total; } public function set page(page) { _page = page; } public function get page() { return _page; } }
import fj.util.JDelegate; import fj.page.JPage; class fj.page.JcreateBtn extends JPage { //四个分页实例 private var _firPage:MovieClip; private var _prePage:MovieClip; private var _nexPage:MovieClip; private var _lasPage:MovieClip; //显示页码信息的实例 public var _pageMsg:MovieClip; //实现跳转功能的例 public var _goTo:MovieClip; public function JcreateBtn(page, total) { _index = page; _page = page; _total = total; } //重新初始化 public function init() { _index = _page; setBtn(); addPageMsg(_pageMsg); addGoTo(_goTo); } //增加按钮事件 public function addButton(firPage, prePage, nexPage, lasPage) { _firPage = firPage; _prePage = prePage; _nexPage = nexPage; _lasPage = lasPage; //默认情况 btnFunc(); var ins = this; firPage.onRelease = function() { ins.firstPage(); ins.btnFunc(); }; prePage.onRelease = function() { ins.prevPage(); ins.btnFunc(); }; nexPage.onRelease = function() { ins.nextPage(); ins.btnFunc(); }; lasPage.onRelease = function() { ins.lastPage(); ins.btnFunc(); }; } //增加显示页码功能:(页数:1/2) public function addPageMsg(p) { _pageMsg = p; var cur = Math.ceil(_index/_page); var tot = Math.ceil(_total/_page); _pageMsg.text = "页数:"+cur+"/"+tot; } //增加跳转功能 public function addGoTo(g) { _goTo = g; _goTo.removeAll(); for (var i = 0; i<_total/_page; i++) { _goTo.addItem({label:i+1, data:i+1}); } _goTo.addEventListener("change", JDelegate.create(this, goToFunc)); } private function btnFunc() { setBtn(_firPage, _prePage, _nexPage, _lasPage); addPageMsg(_pageMsg); _goTo.selectedIndex = Math.ceil(_index/_page)-1; } private function goToFunc() { var t = _goTo.value; _index = t*_page; setBtn(); addPageMsg(_pageMsg); } //设置按钮的可用性 private function setBtn() { if (_page>_total) { //总数小于page noBtn(); } else { if (_index>=_total) { //最后一页 lasBtn(); } else if (_index-_page<=1) { //最前一页 firBtn(); } else { //中间一页 cenBtn(); } } } private function firBtn() { _firPage.enabled = false; _prePage.enabled = false; _nexPage.enabled = true; _lasPage.enabled = true; } private function lasBtn() { _firPage.enabled = true; _prePage.enabled = true; _nexPage.enabled = false; _lasPage.enabled = false; } private function cenBtn() { _prePage.enabled = true; _nexPage.enabled = true; _firPage.enabled = true; _lasPage.enabled = true; } private function noBtn() { _firPage.enabled = false; _prePage.enabled = false; _nexPage.enabled = false; _lasPage.enabled = false; } }
|