[AS3]as3.0用Loader同时下载多张图片的源代码示例
[AS3]as3.0用Loader同时下载多张图片的源代码示例,as3与Loader,as3加载,as3加载图片
[AS3]as3.0用Loader同时下载多张图片的源代码示例,as3与Loader,as3加载,as3加载图片
- package {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.net.URLRequest;
- import flash.display.Loader;
- import flash.events.ProgressEvent;
- import flash.display.Bitmap;
- import fl.controls.Button;
- import flash.events.MouseEvent;
- import flash.utils.getQualifiedClassName;
- import flash.utils.getDefinitionByName;
- import flash.utils.Timer;
- import flash.events.TimerEvent;
- public class PicMc extends Sprite {
- private var loaderArr:Array;
- private var urlArr:Array;
- private var numPic:int=20;
- private var picArr:Array;
- private var pagePic:int=0;
- private var scene:Sprite;
- private var bigDelay:Timer;
- private var bigPic:Sprite;
- public function PicMc():void {
- init();
- }
- private function init():void {
- bigDelay=new Timer(1500,1);
- bigDelay.addEventListener(TimerEvent.TIMER_COMPLETE,endDelay);
- urlArr=new Array();
- var url:URLRequest;
- var path:String="images\\";
- for (var i:uint=0; i <numPic; i++) {
- pathpath=path + detect(i + 1) + ".jpg";
- url=new URLRequest(path);
- urlArr.push(url);
- path="images\\";
- }
- showPage();
- for (i=0; i<Math.ceil(numPic/12); i++) {
- var btn:Button=new Button();
- btn.x=i*20;
- btn.y=310;
- btn.width=18;
- btn.label=(i+1).toString();
- addChild(btn);
- btn.addEventListener(MouseEvent.MOUSE_DOWN,pageDown);
- }
- }
- //CuPlayer.com提示:分页
- private function pageDown(e:MouseEvent):void {
- pagePic=int(e.target.label)-1;
- removeChild(scene);
- showPage();
- }
- private function showPage() {
- scene=new Sprite();
- addChild(scene);
- loaderArr=new Array ;
- var loader:Loader;
- var couPic:int=(numPic-pagePic*12)>12?12:(numPic-pagePic*12);
- for (var i:uint=0; i < couPic; i++) {
- loader=new Loader ;
- loader.load(urlArr[pagePic*12+i]);
- loaderArr.push(loader);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
- }
- picArr=new Array ;
- for (i=0; i < couPic; i++) {
- var picCon:Sprite=new Sprite;
- picCon.x=i % 4 * 100;
- picCon.y=int(i / 4) * 100;
- picCon.graphics.lineStyle(1,0xff0000);
- picCon.graphics.beginFill(0x00ffff);
- picCon.graphics.drawRect(0,0,100,100);
- picCon.graphics.endFill();
- scene.addChild(picCon);
- picArr.push(picCon);
- }
- }
- /*
- private function onOpen(e:Event):void {
- }
- */
- private function onComplete(e:Event):void {
- var i:int=0;
- while (loaderArr[i] != e.target.loader) {
- i++;
- }
- picArr[i].graphics.clear();
- var img:Bitmap=e.target.content;
- img.scaleX=95/img.width;
- img.scaleY=95/img.height;
- picArr[i].addChild(img);
- picArr[i].addEventListener(MouseEvent.MOUSE_DOWN,picDown);
- scene.addChild(picArr[i]);
- }
- private function picDown(e:MouseEvent):void{
- var i:int=0;
- while (picArr[i] != e.target) {
- i++;
- }
- var loader:Loader=new Loader();
- loader.load(urlArr[i]);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,bigComplete);
- }
- private function bigComplete(e:Event):void{
- bigPic=new Sprite();
- bigPic.addChild(e.target.content);
- bigPic.x=(stage.stageWidth-bigPic.width)/2;
- bigPic.y=(stage.stageHeight-bigPic.height)/2;
- addChild(bigPic);
- bigDelay.start();
- }
- private function endDelay(e:TimerEvent):void{
- removeChild(bigPic);
- }
- //CuPlayer.com提示:检测文件名长度
- private function detect(num:int,len:int=2):String {
- var numnumStr:String=num.toString();
- while (numStr.length < len) {
- numStr="0" + numStr;
- }
- return numStr;
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...