发新话题
打印

FLASH类似网页数字跳转组件(好象是这么说明吧)-_-!

FLASH类似网页数字跳转组件(好象是这么说明吧)-_-!

今天在使用LIST组件的时候,发现当LIST项目超过千位左右时,FLASH资源消耗超级大,想到用分页的方式读取,但是如何制作一个类似网页数字跳页的组件呢?

之前没做过,立即动手做做看!

首先这个组件应当是完全动态生成的,包括按钮和数字

其次要方便使用,可以设置显示多少个数字啊,颜色啊,高光颜色等等

使用PageCount设置总页数,NowPage为初始化当前页数,PageStart从第几页开始显示

 

 

附件

分页组件.fla (64 KB)

2006-5-23 07:49, 下载次数: 107

111.gif (1.27 KB)

2006-5-23 07:49

111.gif

222.gif (222 Bytes)

2006-5-23 07:49

222.gif

分页组件.swf (1.13 KB)

2006-5-23 07:49, 下载次数: 107

TOP

Re:FLASH类似网页数字跳转组件(好象是这么说明吧)-_-!

代码不多,70行,其实可以更少的,想出来就做了,懒得去想了,达人就不要看了,遭笑话!

给那些初学者讲解一下,希望各位可以从中发挥一下.

var PageCount:Number=20;//这个值用来设置总的页数
var NowPage:Number=1;//当前页数
var PageStart:Number=1;//从第几页开始
var ShowLimit:Number;//显示多少个数字
var MoveSpeed:Number;//5454
var fontColor;//文字颜色
var HighLight;//高光颜色

/*
下面这几行代码初始化文字的基本颜色和字体
*/
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "宋体";
my_fmt.color = fontColor;

function DefaultColor(){
    my_fmt.color = fontColor;
    for(var i:Number=1;i<=PageCount;i++){
        this["tempMC"]["txt_"+i].setTextFormat(my_fmt);
    }
    my_fmt.color = HighLight;
    this["tempMC"]["txt_"+NowPage].setTextFormat(my_fmt);
}

//开始创建元件
BuildStart();
function BuildStart(){
      //首先创建一个空的MC,为了卸载和重写方便,我常把有可能需要重建或卸载的元件统一放置在一个MC中,这样在需要的时候,只需将此MC卸载即可
     this.createEmptyMovieClip("tempMC",1);
     //根据之前定义好的创建设置,生成元件并相应设置其坐标等
     for(var i:Number=1;i<=PageCount;i++){
        var TxtWidth:Number=i.toString().length*14;//文字筐的宽度,可能会有些不通用
        this["tempMC"].createTextField("txt_"+i,i,(i-1)*14,0,TxtWidth,20);
        this["tempMC"]["txt_"+i].text=i;
        this["tempMC"]["txt_"+i].selectable=false;
        DrawStick("tempMC","btn_"+i, [20,TxtWidth], 0x000000, 0, i*1001) ;//此函数为方便使用的绘制矩形,DrawStick(目标载体, 新元件名称, [高和宽], 颜色, 透明度, 深度)
        this["tempMC"]["btn_"+i]._x=(i-1)*14;
        this["tempMC"]["btn_"+i].data=i;//将数字信息载给按钮,方便使用.
        this["tempMC"]["btn_"+i].onRelease=function(){
            //当点击数字时需要触发的事件写在这里就可以
           NowPage=this.data;
           DefaultColor();
        }
 }
 

//创建遮照用MC,与ShowLimit参数关联
 this.createEmptyMovieClip("maskMC",2);
 DrawStick("maskMC","mask", [20,ShowLimit*14], 0x000000, 100, 100000000);
 this["tempMC"].setMask(maskMC);
 

//创建箭头,其实可以在一开始和文字一起创建,但是MASK时可能会麻烦点,没想太多,先这样吧
 this.createTextField("leftarrow",3,maskMC._x-28,0,28,20);
 this.createEmptyMovieClip("leftbtn",4);
 DrawStick("leftbtn","xxx", [20,18], 0x000000, 0, 1);
 this["leftbtn"]._x=maskMC._x-28;
 this["leftarrow"].text="<<";
 this["leftarrow"].setTextFormat(my_fmt);
 this["leftarrow"].selectable=false;
 
 this.createTextField("rightarrow",5,maskMC._width+10,0,28,20);
 this.createEmptyMovieClip("rightbtn",6);
 DrawStick("rightbtn","xxx", [20,18], 0x000000, 0, 1);
 this["rightbtn"]._x=maskMC._width+10;
 this["rightarrow"].text=">>";
 this["rightarrow"].setTextFormat(my_fmt);
 this["rightarrow"].selectable=false;
 
 this["leftbtn"].onPress=function(){
     if(this._parent["tempMC"]._x<0){
         this._parent["tempMC"]._x+=14;
     }
 }
 this["rightbtn"].onPress=function(){
     if(this._parent["tempMC"]._x>-this._parent["tempMC"]._width+this._parent["maskMC"]._width+18){
         this._parent["tempMC"]._x-=14;
     }
 }
 DefaultColor();
}

 

TOP

Re:FLASH类似网页数字跳转组件(好象是这么说明吧)-_-!

//方便动态绘制矩形的代码 function DrawStick(Target, CreatName, HandW, ColorRGB, Alpha, Depth) { this[Target].createEmptyMovieClip(CreatName, Depth); this[Target][CreatName].beginFill(ColorRGB, Alpha); this[Target][CreatName].lineStyle(0.2, 0xffffff, 0); this[Target][CreatName].moveTo(0, 0); this[Target][CreatName].lineTo(0, HandW[0]); this[Target][CreatName].lineTo(HandW[1], HandW[0]); this[Target][CreatName].lineTo(HandW[1], 0); this[Target][CreatName].lineTo(0, 0); this[Target][CreatName].endFill(); }

TOP

虽然说代码不算多,不过这样看也有点晕哦,所以还是看源文件了~
关于生命与花的寓言……

TOP

发新话题