·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3数组元素如何实现分页功能代码示例

时间:2012-09-14 14:04bbs.9ria.com
[AS3]as3数组元素如何实现分页功能代码示例,as3数组,as3数组分页

用as3实现了数组元素的分页:
代码如下:
Page 类

  1. package pages  
  2. {  
  3.         public class Page  
  4.         {  
  5.                 private var array:Array;  
  6.                 private var _index:int;  
  7.                 private var _capacity:int = 0;  
  8.                 public function Page()  
  9.                 {  
  10.                         array=new Array();  
  11.                 }  
  12.                 /**  
  13.                  *添加  
  14.                  * @param item  
  15.                  *  
  16.                  */  
  17.                 public function add(item:Object):void  
  18.                 {  
  19.                         if (array.length < _capacity)  
  20.                         {  
  21.                                 array.push(item);  
  22.                         }  
  23.                 }  
  24.                 public function get capacity():int  
  25.                 {  
  26.                         return _capacity;  
  27.                 }  
  28.                 /**  
  29.                  *删除  
  30.                  * @param index  
  31.                  * @return  
  32.                  *  
  33.                  */  
  34.  
  35.                 public function remove(index:int):Object  
  36.                 {  
  37.                         var obj:Object = null;  
  38.                         if (index in array)  
  39.                         {  
  40.                                 obj = array.splice(index,1);  
  41.                         }  
  42.                         return obj;  
  43.                 }  
  44.                 /**  
  45.                  *项目索引  
  46.                  * @param item  
  47.                  * @return  
  48.                  */  
  49.                 public function indexOf(item:Object):int  
  50.                 {  
  51.                         var index:int = -1;  
  52.                         for (var i:int=0; i < array.length; i++)  
  53.                         {  
  54.                                 if (item === array[i])  
  55.                                 {  
  56.                                         iindex = i;  
  57.                                         break;  
  58.                                 }  
  59.                         }  
  60.                         return index;  
  61.                 }  
  62.                 /**  
  63.                  *页序号  
  64.                  * @return  
  65.                  *  
  66.                  */  
  67.                 public function get index():int  
  68.                 {  
  69.                         return _index;  
  70.                 }  
  71.                 public function set capacity(capacity:int):void  
  72.                 {  
  73.                         if (capacity >= 0)  
  74.                         {  
  75.                                _capacity = capacity;  
  76.                         }  
  77.                 }  
  78.                 /**  
  79.                  *数量  
  80.                  * @return  
  81.                  *  
  82.                  */  
  83.                 public function get count():int  
  84.                 {  
  85.                        return array.length;  
  86.                 }  
  87.                 /**  
  88.                  *是否为空  
  89.                  * @return  
  90.                  */  
  91.                 public function empty():Boolean  
  92.                 {  
  93.                         return array.length == 0;  
  94.                 }  
  95.                 public function set index(value:int):void  
  96.                 {  
  97.                         if (value >= 0)  
  98.                         {  
  99.                                 _index = value;  
  100.                         }  
  101.                 }  
  102.                 /**  
  103.                  *项目集合  
  104.                  * @return  
  105.                  */  
  106.                 public function get items():Array  
  107.                 {  
  108.                         return array;  
  109.                 }  
  110.                 /**  
  111.                  *页的描述   
  112.                  * @return   
  113.                  */                  
  114.                 public function toString()  
  115.                 {  
  116.                         return array.toString();  
  117.                 }  
  118.         }  
  119. }  

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器