Flash AS3 连续加载外部若干图片
//载入图片
public function loadClassBgPic():void
{
//载入图片没有完毕
bloadBgOver = false;
//从xml数据中读取并计算总的下载量
bmpUrlArr.push(classXml["class"]["pad"]["background"]);
bmpUrlArr.push(classXml["class"]["title"]["background"]);
for(var i:uint = 0; i < classXml["class"]["page"].@count; i++)
{
bmpUrlArr.push(classXml["class"]["page"]["content"][i]["background"]);
}
itotalBmpCount = bmpUrlArr.length;
iloadedBmpCount = 0;
//载入第一个图片
loadBgPic(bmpUrlArr[iloadedBmpCount]);
}
public function loadBgPic(myURL:String):void
{
var rd:int = Math.random()*9999;
//var myURL:String="/file/imgs/upload/202301/31/phgnbyox3zu.jpg";//?"+rd;
var myRequest:URLRequest = new URLRequest(myURL);
var myLoader:Loader = new Loader();
var myVariables:URLVariables = new URLVariables();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadBgPicProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBgPicOK);
myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadBgPicError);
myRequest.method = URLRequestMethod.POST;
myLoader.load(myRequest);
//trace("start load");
}
public function loadBgPicProgress(e:ProgressEvent):void
{
var iloaded:uint = e.bytesLoaded;
var itotal:uint = e.bytesTotal;
text_progress.text = "正在载入图片数据..."+iloaded+" / "+itotal;
}
public function loadBgPicOK(e:Event):void
{
var mload:Loader = Loader(e.target.loader);
var bmp:Bitmap = e.target.content as Bitmap;
//mc_bg.addBmp(bmp);
//mc_bg.mc_content.addChild(bmp);
bmp.width = 800;
bmp.height = 600;
mload.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,loadBgPicProgress);
mload.contentLoaderInfo.removeEventListener(Event.COMPLETE,loadBgPicOK);
//图片载入完毕,存储到MC数组中
bmpArr[iloadedBmpCount] = new MovieClip();
bmpArr[iloadedBmpCount].addChild(bmp);
//将该图片mc设定到背景里面去
mc_bg.addChild(bmpArr[iloadedBmpCount]);
bmpArr[iloadedBmpCount].visible = false;
iloadedBmpCount++;
if(iloadedBmpCount < itotalBmpCount)
{
//载入下一个图片
loadBgPic(bmpUrlArr[iloadedBmpCount]);
}else
{
iloadedBmpCount = 0;
bloadBgOver = true;
}
showClassBgOver();
}
public function loadBgPicError(e:IOErrorEvent):void
{
//图片载入失败,创建空mc
bmpArr[iloadedBmpCount] = new MovieClip();
//将该图片mc设定到背景里面去
mc_bg.addChild(bmpArr[iloadedBmpCount]);
bmpArr[iloadedBmpCount].visible = false;
var txt:TextField = new TextField();
txt.text = "该图片载入失败";
bmpArr[iloadedBmpCount].addChild(txt);
iloadedBmpCount++;
//载入下一个图片
if(iloadedBmpCount < itotalBmpCount)
{
//载入下一个图片
loadBgPic(bmpUrlArr[iloadedBmpCount]);
}else
{
iloadedBmpCount = 0;
bloadBgOver = true;
}
showClassBgOver();
}
//载入背景图片完毕,根据当前所处状态切换显示不同背景
public function showClassBgOver():void
{
for(var j:uint = 0; j < bmpArr.length; j++)
{
bmpArr[j].visible = false;
}
switch(gameState)
{
case "classPad":
//题目面板
bmpArr[0].visible = true;
break;
case "inclass":
//题目主题界面
bmpArr[1].visible = true;
break;
case "classpage":
//课程页面,根据当前不同页号显示不同背景
var temp:uint = ipage + 2;
bmpArr[temp].visible = true;
break;
}
}
以上!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341