当前位置:软件学习 > Flash >>

as.2 flash图片加载效果

as.2 flash图片加载效果

package {
import flash.display.sprite;
import flash.events.event;
import flash.events.mouseevent;
import flash.events.progressevent;
import flash.display.bitmap;
import flash.display.bitmapdata;
import flash.display.易做图button;
import flash.display.loader;
import flash.net.urlloader;
import flash.net.urlrequest;
import fl.transitions.tween;
import fl.transitions.easing.elastic;
public class sampleshowpic extends sprite {
  private var page:uint;
  private var size:uint;
  private var total:uint;
  private var posx:number;
  private var posy:number;
  private var pos_sprite:sprite;
  private var thuns_sprite:sprite;
  private var show_bitmap:bitmap;
  private var list_xml:xml;
  private var xml_loader:urlloader;
  private var start_b:boolean;
  public function sampleshowpic():void {
   init();
  }
  private function init():void {
   page=1;
   size=4;
   show_bitmap=new bitmap  ;
   xml_loader=new urlloader  ;
   thuns_sprite=new sprite  ;
   addchild(thuns_sprite);
   xml_loader.addeventlistener(event.complete,onxmlloadcomplete);
   xml_loader.load(new urlrequest("teamshow.xml"));
   prev_btn.addeventlistener(mouseevent.click,onbtnclick);
   next_btn.addeventlistener(mouseevent.click,onbtnclick);
  }
  private function onxmlloadcomplete(_evt:event):void {
   list_xml=xml(_evt.target.data);
   total=list_xml.children().length();
   show_func();
  }
  private function show_func():void {
   removechild(thuns_sprite);
   thuns_sprite=new sprite  ;
   addchild(thuns_sprite);
   for (var p:uint=0; p < size; p++) {
    var _p:uint=(page - 1) * size + p;
    if (_p >= total) {
     return;
    }
    var _info:infosprite=new infosprite  ;
    _info.x=442,_info.y=p * 110 + 80;
    _info.time_txt.text=list_xml.content[_p].time;
    _info.titl_txt.text=list_xml.content[_p].casetitle;
    loadpic_func(list_xml.content[_p].url,string(p));
    thuns_sprite.addchild(_info);
   }
  }
  private function loadpic_func(_str:string,_n:string):void {
   var _loaderoader=new loader  ;
   _loader.contentloaderinfo.addeventlistener(event.complete,onpicloadcomplete);
   _loader.contentloaderinfo.addeventlistener(progressevent.progress,onpicloadprogress);
   _loader.load(new urlrequest(_str));
   _loader.name=_n;
  }
  private function onpicloadprogress(_evtrogressevent):void {
   trace("pro=" + _evt.bytesloaded/ _evt.bytestotal*100);
  }
  private function onpicloadcomplete(_evt:event):void {
   var _n:uint=uint(_evt.target.loader.name);
   var _pic:bitmap=_evt.target.content  as  bitmap;
   _pic.width=96;
   _pic.height=56;
   var _sprite:sprite=new sprite  ;
   _sprite.x=442;
   _sprite.y=_n * 110 + 80;
   _sprite.addchild(_pic);
   _sprite.buttonmode=true;
   _sprite.addeventlistener(mouseevent.click,onpicclick);
   ! start_b && (start_b=true) && _sprite.dispatchevent(new mouseevent(mouseevent.click));
   thuns_sprite.addchild(_sprite);
  }
  private function onpicclick(_evt:mouseevent):void {
   var _sprite:sprite=_evt.target  as  sprite;
   var _pic:bitmap=_sprite.getchildat(0)  as  bitmap;
   show_bitmap.bitmapdata=_pic.bitmapdata.clone();
   if (pos_sprite) {
    var _tweenpx:tween=new tween(pos_sprite,"x",elastic.easeo教程ut,pos_sprite.x,posx,18,false);
    var _tweenpy:tween=new tween(pos_sprite,"y",elastic.easeout,pos_sprite.y,posy,18,false);
   }
   posx=_sprite.x,posy=_sprite.y,pos_sprite=_sprite;
   var _tweenx:tween=new tween(_sprite,"x",elastic.easeout,posx,217,18,false);
   var _tweeny:tween=new tween(_sprite,"y",elastic.easeout,posy,245,18,false);
   var x_tween:tween=new tween(show_bitmap,"x",elastic.easeout,217,22,18,false);
   var y_tween:tween=new tween(show_bitmap,"y",elastic.easeout,245,20,18,false);
   var w_tween:tween=new tween(show_bitmap,"width",elastic.easeout,96,390,18,false);
   var h_tween:tween=new tween(show_bitmap,"height",elastic.easeout,56,470,18,false);
   addchild(show_bitmap);
  }
  private function onbtnclick(_evt:mouseevent):void {
   var _btn:易做图button=_evt.target  as  易做图button;
   switch (_btn) {
    case prev_btn :
     if (page > 0) {
      page--;
      show_func();
     }
     break;
    case next_btn :
     if (page < math.ceil(total / size)) {
      page++;
      show_func();
     }
     break;
   }
  }
}
}

补充:flash教程,动画技术
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,