flash分页技术(相册)

 

图:
 
Code:
  package {
 import flash.display.MovieClip;

 import flash.display.Loader;
 import flash.net.URLLoader;
 import flash.net.URLRequest;

 import flash.events.MouseEvent;
 import flash.events.Event;
 import flash.display.JointStyle;
 import flash.display.LoaderInfo;
 import flash.display.DisplayObject;
 public class paging extends MovieClip {
  private var request:URLRequest;
  private var loader:URLLoader;
  private var xmlList:XMLList;
  private var lengths:int;
  private var pages:int=1;
  private var picurl:URLRequest;
  private var picLoader:Loader;
  private var ct:CT;
  private var mc:MovieClip=new MovieClip();
  private var mc1:DisplayObject;
  
  private var targetX:Number;
  private var targetY:Number;
  private var picX:Number;
  private var picY:Number;
  private var picW:Number=80;
  private var picH:Number=57;
  public function paging() {
   XMLLoader();
  }
//加载XML文件
  private function XMLLoader():void {
   request=new URLRequest("img.xml");
   loader=new URLLoader();
   loader.load(request);
   loader.addEventListener(Event.COMPLETE,xmlhandler);
  }
  private function xmlhandler(e:Event):void {
   xmlList=XMLList(e.target.data);
   lengths=xmlList.img.length();
   trace(lengths);
   picHandler();
   prepage_btn.addEventListener(MouseEvent.CLICK,prehandler);
   nextpage_btn.addEventListener(MouseEvent.CLICK,nexthandler);
  }
//前一页
  private function prehandler(e:MouseEvent):void {
   if (pages>1) {
    pages-=1;
   }
   picHandler();
  }
//后一页
  private function nexthandler(e:MouseEvent):void {
   if (pages<Math.ceil(lengths/21)) {
    pages+=1;
   }
   picHandler();
  }
//分页加载图片
  private function picHandler():void {
   pages_btn.text=String(pages);
   try {
    removeChild(ct);
    ct=null;
   } catch (e) {
   }
   ct=new CT();
   addChild(ct);
   ct.addEventListener("click",cthandler);
   ct.x=6;
   ct.y=9;
   for (var i:int=0; i<7; i++) {
    for (var j:int=0; j<3; j++) {
     if (21*(pages-1)+i*3+j<lengths) {
      picurl=new URLRequest(xmlList.img[21*(pages-1)+i*3+j].url);
      trace(i*j*(pages-1));
      picLoader=new Loader();
      picLoader.load(picurl);
      picLoader.x=20+80*j;
      picLoader.y=20+57*i;
      ct.addChild(picLoader);
      picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,pichandler);
     }
    }
   }
  }
  private function cthandler(e:MouseEvent):void {
   try {
    ct.addChild(mc1);
    mc1.x=picX;
    mc1.y=picY;
    mc1.width=picW;
    mc1.height=picH;
   } catch (e) {
   }
   trace(e.target.name.substr(2,1));
   if (e.target.name!=e.currentTarget.name) {
    mc1=DisplayObject(e.target);
    e.target.width=targetX;
    picX=e.target.x;
    picY=e.target.y;
    e.target.x=15;
    e.target.y=15;
    e.target.height=targetY;
    containers.addChild(mc1);
   }
  }
  private function pichandler(e:Event):void {
   var loaderinfo:LoaderInfo=e.target as LoaderInfo;
   targetX=loaderinfo.content.width;
   targetY=loaderinfo.content.height;
   loaderinfo.content.width=80;
   loaderinfo.content.height=57;
  }
 }
}
 

 

你可能感兴趣的:(.net,xml,Flash,J#)