//=========初始化==========
stop();
//页数,默认0表示第一页
var curPage_num:Number = 0;
//每页容量
var sizPage_num:Number = 15;
var countPage:int;
var countImage:int;
var currentImages:Array=[];
//每排张数
var pai_num:Number = 5;
//图片宽度、高度
var width_num:Number = 80;
var height_num:Number = 80;
//图片与图片之间的间隔
var jia_num:Number = 20;
//=============================
var url_array:Array = new Array();
var my_xml:XML;
var my_urlloader:URLLoader=new URLLoader();
my_urlloader.load(new URLRequest(“xml/img.xml”));
my_urlloader.addEventListener(Event.COMPLETE,_showxml);
function _showxml(e):void {
  my_xml=new XML(e.currentTarget.data);
  for (var i:uint=0; i<my_xml.pic.length(); i++) {
    var my_Obj:Object = new Object();
    my_Obj.src = my_xml.pic[i].@name;
    url_array.push(my_Obj);
  }
  countImage=url_array.length;
  countPage=Math.ceil(countImage/sizPage_num);
  show_func(0);
}

function remvoeAllImages():void {
  var len:int=currentImages.length;
  var item:DisplayObject;
  for (var i:int=0; i< len; i++) {
    item=currentImages[i];
    removeChild(item);
    item=null;
  }
  currentImages=[];
}
function show_func(_page:Number) {
  remvoeAllImages();
  var my_loader:Loader;
  var startIndex:int=curPage_num*sizPage_num;
  var endIndex:int=startIndex+sizPage_num;
  if (endIndex>countImage-1) {
    endIndex=countImage;
  }
  for (var d:Number = startIndex; d<endIndex; d++) {
    my_loader=new Loader();
    var tmp:MovieClip = new MovieClip();
    tmp.x = 20+d%pai_num*(width_num+jia_num);
    tmp.y = 20+Math.floor((d-startIndex)/pai_num)*(height_num+jia_num);
    my_loader.load(new URLRequest(url_array[d].src));
    tmp.addChild(my_loader);
    tmp.addEventListener(MouseEvent.CLICK,_trace);
    addChild(tmp);
    tmp._i=d;
    currentImages.push(tmp);
    function _trace(e:MouseEvent):void {
      trace(e.currentTarget.name);
      txt_show.text=”您选择了第:”+e.currentTarget._i+”张相片”;
    }
  }

}
function _next(e:MouseEvent) {

  if (curPage_num< countPage-1) {
    curPage_num++;
    show_func(curPage_num);

  }

}
function _pre(e:MouseEvent) {
  if (curPage_num>0) {
    curPage_num–;
    show_func(curPage_num);

  }
}
btn_pre.txt.text=”上一页”;
btn_next.txt.text=”下一页”;
btn_pre.txt.selectable=false;
btn_next.txt.selectable=false;
btn_pre.addEventListener(MouseEvent.CLICK,_pre);
btn_next.addEventListener(MouseEvent.CLICK,_next);

    博视界科技专注于沉浸式全景数字餐厅、全息酒店宴会厅,旨在帮传统餐饮用科技玩跨界,欢迎咨询!

官方网站:www.boseetech.com

联系方式:    

关注我们:


    【声明】转载本文请注明出处三人行设计,并保留有效链接:[Flash AS3实例教程]简单的flash+xml相册实例 http://www.srxtuan.com/archives/1030,谢谢!

猜您还喜欢: