论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

AS2.0写的分页程序

文章类别:Flash AS编程 | 发表日期:2008-10-6 17:35:51


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;
    }
}

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058