这是一个用MovieClipLoader连续加载外部图片并进行控制的实例。
varselectedmc;
varid=1;
varNum=13;
varmyML:MovieClipLoader=newMovieClipLoader();
varmyL:Object=newObject();
myL.onLoadComplete=function(target:MovieClip){
if(id==1)target._visible=true;
elsetarget._visible=false;
_root["imgBtn"+id+"_btn"].label=id;
trace(_root["imgBtn"+id+"_btn"]);
id++;
if(id<Num){
loadpic(id);
}else{
//for(vari=;i<Num,i++){
//}
}
}
myL.onLoadInit=function(target:MovieClip){
target._width=400;
target._height=300;
target._x=(540-400)/2;
target._y=30;
}
myL.onLoadProgress=function(target:MovieClip,bytesLoaded:Number,bytesTotal:Number){
_root["imgBtn"+id+"_btn"].label=Math.round(100*bytesLoaded/bytesTotal)+"%";
}
myML.addListener(myL);
functionloadpic(n){
varname_btn="imgBtn"+n+"_btn";
varname_mc="imgMc"+n+"_mc";
name_btn=_root.attachMovie("Button",name_btn,_root.getNextHighestDepth());
name_mc=_root.createEmptyMovieClip(name_mc,_root.getNextHighestDepth());
name_mc.id=n;
name_btn.setSize(35,22);
name_btn._x=10+(n-1)*40;
name_btn._y=360;
name_btn.toimg=name_mc;
name_btn.onPress=function(){
selectedmc._visible=false;
selectedmc=this.toimg;
selectedmc._visible=true;
}
varn2=n;
if(Number(n2)<10)n2="0"+n2;
//myML.loadClip("http://www.pconline.com.cn/pcedu/photo/0604/pic/060428vistawwp0"+n+"-b.jpg",name_mc);
myML.loadClip("http://www.pconline.com.cn/pcedu/photo/0604/pic/060428fruit"+n2+".jpg",name_mc);
}
btn.label="导入";
btn.onPress=function(){
loadpic(id);
}