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

as 3.0调用多图片loading 代码

这是一款as 3.0调用多图片loading 代码哦,它调用的是xml文件里面图片路径。

stop();
var sp:Sprite=new Sprite(),url_array:Array=[],title_array:Array=[],getUrl_array:Array=[];
addChild(sp);
//------------- 导入XML数据资料区 --------------------------------------
var XML_URL:String = "http://sxl001.xfyun.com/Images.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
var xmlLong:uint;
function xmlLoaded(event:Event):void {
  var myXML:XML = XML(myLoader.data);
  xmlLong =myXML.image.child("image").length();
  for (var i:uint =0; i<xmlLong; i++) {
    url_array.push([myXML.image.image[i].@title,myXML.image.image[i].@url]);
  }
  var getUrlLong:uint =myXML.getUrl.child("getUrl").length();
  for (var j:uint =0; j<getUrlLong; j++) {
    getUrl_array.push(myXML.getUrl.getUrl[j].@url);
  }
  event.target.removeEventListener("complete", xmlLoaded);
  init(xmlLong);
}
function init(long:uint) {
  for (var j:uint=0; j<long; j++) {
    var loader:Loader = new Loader();
    initLoad(loader,j);
  }
}
function initLoad(loader:Loader,i:uint) {
  var target:bg_mc=new bg_mc();
  target.x=140*i-(Math.floor(i/5)*700);
  target.y=183*Math.floor(i/5);
  target.i=i;
  sp.addChild(target);
  loader.load(new URLRequest(url_array[i][1]));
  loader.addEventListener(Event.INIT, initHandler);
  loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
  loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
  function loadProgress(event:ProgressEvent):void {
    var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*10000)/100;
    target.title_txt.text=percent+" %";
    target.title_txt.mouseEnabled=false;
  }
  function loadComplete(event:Event):void {
    var loadBitmap:Loader=Loader(event.target.loader);
    var image:Bitmap=Bitmap(loadBitmap.content);
    image.width=140;
    image.height=183;
    target.addChild(image);
    target.mc.stop();
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loadComplete);
    loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
  }
}

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