as3加载图片
2011-09-02 17:08 sniper007 阅读(190) 评论(0) 编辑 收藏 举报package{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.display.MovieClip;
public class imgload extends Sprite
{
private var list:Array,img:Array;
private var v_width:int=92;
private var v_height:int=107;
private var count:Number=0;
public function imgload():void
{
list = new Array();
img = new Array();
loadImg();
}
public function loadImg():void
{
list = ["1","2","3"];
for(var i:int=0;i<list.length;i++)
{
var loadimg:Loader = new Loader();
loadimg.name = "loadimg"+i;
var url:String = "img/img0"+list[i]+".jpg";
trace(url);
loadimg.load(new URLRequest(url));
img.push(loadimg);
}
addListen(img);
}
public function addListen(loadarry:Array):void
{
for(var i:int=0;i<loadarry.length;i++)
{
loadarry[i].contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
}
}
public function onLoadComplete(e:Event):void
{
var l:Loader = e.target.loader;
var mc:MovieClip = new MovieClip();
mc.addChild(l);
mc.width=t_width;
mc.height=t_height;
mc.addChild(l);
mc.x=100;
mc.y=count;
addChild(mc);
count = count+t_height;
}
}
}
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.display.MovieClip;
public class imgload extends Sprite
{
private var list:Array,img:Array;
private var v_width:int=92;
private var v_height:int=107;
private var count:Number=0;
public function imgload():void
{
list = new Array();
img = new Array();
loadImg();
}
public function loadImg():void
{
list = ["1","2","3"];
for(var i:int=0;i<list.length;i++)
{
var loadimg:Loader = new Loader();
loadimg.name = "loadimg"+i;
var url:String = "img/img0"+list[i]+".jpg";
trace(url);
loadimg.load(new URLRequest(url));
img.push(loadimg);
}
addListen(img);
}
public function addListen(loadarry:Array):void
{
for(var i:int=0;i<loadarry.length;i++)
{
loadarry[i].contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
}
}
public function onLoadComplete(e:Event):void
{
var l:Loader = e.target.loader;
var mc:MovieClip = new MovieClip();
mc.addChild(l);
mc.width=t_width;
mc.height=t_height;
mc.addChild(l);
mc.x=100;
mc.y=count;
addChild(mc);
count = count+t_height;
}
}
}