代码不多,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();
}