[AS3]AS3加载XML带进度加载图片类的使用
[AS3]AS3加载XML带进度加载图片类的使用,AS3加载XML,AS3加载图片
1.首先as类文件loadPicture.as
- package
- {
- import flash.net.*;
- import flash.display.*;
- import flash.events.Event;
- import flash.events.TimerEvent;
- import flash.events.ProgressEvent;
- import flash.utils.Timer;
- import fl.transitions.easing.*;
- import fl.transitions.*;
- /*
- http://www.cuplayer.com
- */
- public class loadPicture extends MovieClip
- {
- private var picLoader:Loader = new Loader();
- private var timer:Timer = new Timer(30,10);
- private var imgWnow:Number;
- private var imgHnow:Number;
- private var loadMC:MovieClip;
- public function loadPicture(picUrl:String,imgW:Number,imgH:Number,_loadMC:MovieClip)
- {
- loadMC = _loadMC;
- loadMC.visible = true;
- imgWimgWnow = imgW;
- imgHimgHnow = imgH;
- //图片在舞台上显示的位置
- picLoader.x = 100;
- picLoader.y = 70;
- var urlReq:URLRequest = new URLRequest(picUrl);
- picLoader.load(urlReq);
- picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoader);
- picLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imgLoading);
- }
- //加载完成;
- private function imgLoader(evt:Event):void
- {
- //图片高宽等属性
- picLoader.width = imgWnow;
- picLoader.height = imgHnow;
- picLoader.alpha = 0;
- //图片添加到舞台
- addChild(picLoader);
- imgAlphaTimer();
- var myTween:Tween = new Tween(picLoader,"alpha",Strong.easeInOut,0,1,0.7,true);
- loadMC.visible = false;
- }
- //加载中
- private function imgLoading(evt:ProgressEvent):void
- {
- var _data:int = evt.bytesLoaded / evt.bytesTotal * 100;
- //loading_txt.text = _data + "%";
- }
- //===图片渐显效果
- private function imgAlphaTimer():void
- {
- timer.addEventListener(TimerEvent.TIMER,imgAlphaTimerEvent);
- timer.start();
- }
- private function imgAlphaTimerEvent(evt:TimerEvent):void
- {
- picLoader.alpha += 0.1;
- if (picLoader.alpha > 0.9)
- {
- picLoader.alpha = 1;
- evt.target.stop();
- }
- }
- //==========================end===
- }
- }
2.在FLA文件某帧插入代码,并且FLA文件包含两个剪辑元件,名字为nowLoading(进度条),contentLoader(加载图片的容器)
- import flash.events.Event;
- import loadPicture;
- //加载信息
- var _mainMenuXML:XML;
- var XMLLoader:URLLoader;
- var XMLURL:URLRequest;
- XMLURL = new URLRequest("c945_bg.xml");
- XMLLoader = new URLLoader();
- XMLLoader.load(XMLURL);
- XMLLoader.addEventListener("complete",loadedXML);
- function loadedXML(e:Event)
- {
- _mainMenuXML = new XML(e.target.data);
- var img_:* = _mainMenuXML.imgSrc[0].src;
- var img_W:* = _mainMenuXML.imgSrc[0]. @ width;
- var img_H:* = _mainMenuXML.imgSrc[0]. @ height;
- var img_xExcursion:* = _mainMenuXML.imgSrc[0]. @ xExcursion;
- var img_yExcursion:* = _mainMenuXML.imgSrc[0]. @ yExcursion;
- //信息加载
- var myshow:loadPicture = new loadPicture(img_,img_W,img_H,this.nowLoading);
- myshow.x = img_xExcursion;
- myshow.y = img_yExcursion;
- contentLoader.addChild(myshow);
- }
3.contect.xml文件代码
- <?xml version="1.0" encoding="utf-8" ?>
- <main>
- <imgSrc width="200" height="200">
- <src>img/1.jpg</src>
- </imgSrc>
- <imgSrc width="200" height="200">
- <src>img/2.jpg</src>
- </imgSrc>
- <imgSrc width="200" height="200">
- <src>img/3.jpg</src>
- </imgSrc>
- </main>
4.OK了,这样就完成一个XML带进度加载图片类的使用,很简单的哦
热门文章推荐
- [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示例
请稍候...