一个载入SWF和图片到数组的loader

com.paizi,这个没用可以删掉。给自己留个地方,怕以后忘了。
package {
    import com.paizi;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import fl.transitions.*;
	import fl.transitions.easing.*;
	import flash.events.ProgressEvent;	
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.net.URLLoader;
	import flash.display.Bitmap;

    public class main extends MovieClip {
		private var _bitmap:Bitmap;
		private var ldr:Loader = new Loader();
		private var urlarray:Array = [
			"http://html.moko.cc/html/movie/index.swf",
			"http://img.moko.cc/users/0/4/1451/images/post/src/c826dfca-a11a-423e-bc97-89f7f3ccb0bb.jpg",
			"http://img.moko.cc/users/0/4/1451/images/post/src/e3c9009b-c1ff-4efa-8a33-8cd7510d73e8.jpg",
			"http://img.moko.cc/users/0/4/1451/images/post/src/2483e788-b750-4e39-9b20-7a4b7b15f151.jpg",
			];
		private var urlreuqest:URLRequest;
		private var loader:Loader;
		private var num:int = 0;
		//载入成功的图片数目;
		private var sucessNum:int = 0;
		private var timer:Timer = new Timer(5000,0);
		private var imgarray:Array = [];
		private var urlReq:Array = [];
        public function main():void {
			//添加招牌mc
			addPaizi();
			
			//加载图片
			//侦听
			//timer.addEventListener(TimerEvent.TIMER, change_or_load);
			loadImg();
			//开始
			//timer.start();
			
        }
		public function loadImg():void
		{
			for (var i:uint = 0; i < urlarray.length; i++)
			{
				loader = new Loader();
				loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, funLoadImgProgress);
				loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, funLoadIo_Error);
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, funLoadImgComplete);
				//创建urlreuqest对象
				urlreuqest = new URLRequest(urlarray[i]+"?"+Math.random()*6);
				//载入
				loader.load(urlreuqest);
				loadMv.loadTxt.text = urlarray.length + "/" + (sucessNum);
				//初始化进度条
				loadMv.loadBg.width = 1;
			}
		}
		//载入图片时IO错误
		private function funLoadIo_Error(event:IOErrorEvent):void
		{
			trace("载入图片时错误:" + event);
		}
		//载入进度
		private function funLoadImgProgress(event:ProgressEvent):void
		{
			trace(event.target.loader.contentLoaderInfo.bytesLoaded + "字节");
			var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
			percentLoaded = Math.round(percentLoaded * 100);
			loadMv.loadBg.width = percentLoaded;
			//trace("Loading: "+percentLoaded+"%");
		}
		
		//载入完成
		private function funLoadImgComplete(event:Event):void
		{
			sucessNum++;
			loadMv.loadTxt.text = urlarray.length+ "/"+(sucessNum);
			//loadMv.loadBg.width = 100;
			if (sucessNum == urlarray.length) {				
				loadMv.alpha = 0;
			}
			//添加到 imgarray数组
			imgarray.push(event.target.loader);			
			trace("共"+event.target.loader.contentLoaderInfo.bytesTotal+"  :字节");
			trace(event.target.loader+"  :载入完成");
			trace(sucessNum+"张图片");
			if (sucessNum == urlarray.length)
			{
				funPlay();
			}
		}
		//开始播放
		private function funPlay():void
		{
			//加载图片
			//侦听
			timer.addEventListener(TimerEvent.TIMER, funLoadImg);
			function funLoadImg():void
			{	
				trace("num计数:"+num);
				if(img.numChildren > 0){
					img.removeChildAt(0);
				}
				//添加到舞台影片img
				img.addChild(imgarray[num]);
				funTransition(img);	
				
				num++;
				//取余数,让num永远小于在urlarray.length
				num = num % urlarray.length;
			}
			//计时器开始
			timer.start();
		}
		//添加牌子
		private function addPaizi():void
		{
			var zhaopai:paizi = new paizi();
			zhaopai.x = 400;
			zhaopai.y = 398;
			zhaopai.buttonMode = true;
			this.addChild(zhaopai);
		}
		private function funTransition(_mc:MovieClip):void
		{
			var ran:Number;
			ran =Math.round( Math.random() * 10 );
			switch (ran) 
			{
				case 1 :
					TransitionManager.start(_mc,{type:Blinds, direction:Transition.IN, duration:2, easing:None.easeNone, numStrips:20, dimension:0});
					break;
				case 2 :
					TransitionManager.start(_mc,{type:Blinds, direction:Transition.IN, duration:2, easing:None.easeNone, numStrips:20, dimension:1});
					break;
				case 3 :
					TransitionManager.start(_mc, {type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:1, shape:Iris.CIRCLE});
					break;
				case 4 :
					TransitionManager.start(_mc, {type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:2, shape:Iris.SQUARE});
					break;
				case 5 :
					TransitionManager.start(_mc, {type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:5, shape:Iris.CIRCLE});
					break;
				case 6 :
					TransitionManager.start(_mc, {type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:8, shape:Iris.SQUARE});
					break;
				case 7 :
					TransitionManager.start(_mc, {type:Fade, direction:Transition.IN, duration:9, easing:Strong.easeOut});
				case 8 :
					TransitionManager.start(_mc, {type:PixelDissolve, direction:Transition.IN, duration:2, easing:Regular.easeIn, xSections:10, ySections:10});
					break;
				case 9 :
					TransitionManager.start(_mc, {type:Zoom, direction:Transition.IN, duration:2, easing:Elastic.easeOut});
				default :
					TransitionManager.start(_mc, {type:Wipe, direction:Transition.IN, duration:2, easing:None.easeNone, startPoint:1});
					break;
			}
		}
    }
}

你可能感兴趣的:(.net,Flash)