[AS3]加载图片与SWF动画的播放器
[AS3]加载图片与SWF动画的播放器,当前显示的是哪个类别,此参数作为翻页时的临时中间变量
舞台大小:640*450
- /********************************************************************
- Author: Whb Studio
- Time: 2009-10-1
- QQ: 124257207
- Memo: 版权没有,欢迎转载。
- ********************************************************************/
- System.useCodePage=true;//编码支持中文.
- import fl.containers.UILoader;
- import fl.controls.Button;
- import flash.net.*;
- /********************************************************************
- 定义变量
- ********************************************************************/
- //读XML文件所用变量。
- var whbxml:XML;
- var listcount:int=0;//文件总数量
- var currentpage:int=1;//当前第几页
- var totalpage:int=1;//总共几页
- var currentclass:String;//当前显示的是哪个类别,此参数作为翻页时的临时中间变量。
- var list_x:int=80;//列表的X位置
- var list_y:int=345;//列表的Y位置
- var list_margin:int=10;//列表中各小图片之间的间隔
- var smallmc_w:int=80;//列表中小图片的宽度
- var smallmc_h:int=80;//列表中小图片的高度
- var xmlloader:URLLoader=new URLLoader(new URLRequest("PlayList.xml"));
- //用于加载外部xml文件
- xmlloader.addEventListener(Event.COMPLETE,completeHandler);
- xmlloader.addEventListener(IOErrorEvent.IO_ERROR,xmlloadError);
- //定义3个按钮,用来显示XML中的不同种类
- var pic_btn:Button=new Button();
- var other_btn:Button=new Button();
- var swf_btn:Button=new Button();
- //定义6个UILoader,1大5小
- var bigmc:UILoader=new UILoader();
- var smallmc1:UILoader=new UILoader();
- var smallmc2:UILoader=new UILoader();
- var smallmc3:UILoader=new UILoader();
- var smallmc4:UILoader=new UILoader();
- var smallmc5:UILoader=new UILoader();
- /********************************************************************
- *所有对象的监听事件在本区域添加,请着重理解addEventListener带参传递的用法
- ********************************************************************/
- pic_btn.addEventListener(MouseEvent.MOUSE_DOWN,loadclass("pic"));
- other_btn.addEventListener(MouseEvent.MOUSE_DOWN,loadclass("other"));
- swf_btn.addEventListener(MouseEvent.MOUSE_DOWN,loadclass("swf"));
- next_btn.addEventListener(MouseEvent.MOUSE_DOWN,nextpage);
- prev_btn.addEventListener(MouseEvent.MOUSE_DOWN,prevpage);
- smallmc1.addEventListener(MouseEvent.MOUSE_DOWN,smalltobig(smallmc1));
- smallmc2.addEventListener(MouseEvent.MOUSE_DOWN,smalltobig(smallmc2));
- smallmc3.addEventListener(MouseEvent.MOUSE_DOWN,smalltobig(smallmc3));
- smallmc4.addEventListener(MouseEvent.MOUSE_DOWN,smalltobig(smallmc4));
- smallmc5.addEventListener(MouseEvent.MOUSE_DOWN,smalltobig(smallmc5));
- bigmc.addEventListener(ProgressEvent.PROGRESS, progressHandler);//监视加载进度
- bigmc.addEventListener(Event.COMPLETE, bigcompleteHandler);
- /********************************************************************
- 定义相关函数
- ********************************************************************/
- //函数功能:实现addEventListener带参传递
- function loadclass(parm:String):Function {
- var func=function(e:Event):void{
- currentclass=parm;
- //计算页面导航信息中所用到的数据
- currentpage=1;
- listcount=whbxml.descendants(parm).descendants("file").length();//得到文件总数
- totalpage=Math.ceil(listcount/5);
- //计算完毕,显示第1页
- Showcontent(currentpage);
- };
- return func;
- }
- //函数功能:根据页数显示内容。
- function Showcontent(pageparm:int) {
- UnloadAll();
- try {
- smallmc1.source=whbxml.descendants(currentclass).file[pageparm*5-5].@picurl;
- smallmc2.source=whbxml.descendants(currentclass).file[pageparm*5-4].@picurl;
- smallmc3.source=whbxml.descendants(currentclass).file[pageparm*5-3].@picurl;
- smallmc4.source=whbxml.descendants(currentclass).file[pageparm*5-2].@picurl;
- smallmc5.source=whbxml.descendants(currentclass).file[pageparm*5-1].@picurl;
- } catch (e) {
- } finally {
- bigmc.source=smallmc1.source;
- name_txt.text=whbxml.descendants(currentclass).file[currentpage*5-5].@name;
- list_txt.text="5 条/页,第 "+currentpage+" 页 , 共 "+totalpage+" 页";
- }
- }
- //函数功能:Xml配置文件加载成功
- function completeHandler(e:Event) {
- var getLoader:URLLoader=e.target as URLLoader;
- if (getLoader!=null) {//如果找到了xml配置文件
- whbxml=new XML(getLoader.data);//此时,外部的xml数据被完全转存到内存whbxml文件中
- initsys();//初始化界面
- }
- }
- //函数功能:捕获Xml配置文件加载异常(主要是URL错误异常)
- function xmlloadError(evt:IOErrorEvent) {
- evt.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR,xmlloadError);
- loader_txt.text="未能找到播放列表配置文件!";
- }
- function progressHandler(e:ProgressEvent):void {
- var uiLdr:UILoader = e.currentTarget as UILoader;
- loader_txt.text="正在加载数据:"+Math.round(bigmc.percentLoaded) + "%";
- }
- function bigcompleteHandler(event:Event):void {
- loader_txt.visible = false;
- }
- //函数功能:实现addEventListener带参传递
- function smalltobig(parm:Object):Function {
- var func=function(e:Event):void{
- bigmc.unload();
- bigmc.source=parm.source;
- switch(parm.name){
- case "instance25":
- name_txt.text=whbxml.descendants(currentclass).file[currentpage*5-5].@name;
- break;
- case "instance29":
- name_txt.text=whbxml.descendants(currentclass).file[currentpage*5-4].@name;
- break;
- case "instance33":
- name_txt.text=whbxml.descendants(currentclass).file[currentpage*5-3].@name;
- break;
- case "instance37":
- name_txt.text=whbxml.descendants(currentclass).file[currentpage*5-2].@name;
- break;
- case "instance41":
- name_txt.text=whbxml.descendants(currentclass).file[currentpage*5-1].@name;
- break;
- }
- };
- return func;
- }
- //函数功能:处理用户点击prev_btn事件
- function prevpage(evt:MouseEvent) {
- currentpage--;
- if (currentpage<1) {
- currentpage=1;
- }
- Showcontent(currentpage);
- }
- //函数功能:处理用户点击next_btn事件
- function nextpage(evt:MouseEvent) {
- currentpage++;
- if (currentpage>totalpage) {
- currentpage=1;
- }
- Showcontent(currentpage);
- }
- //函数功能:系统初始化
- function initsys() {
- pic_btn.y=other_btn.y=swf_btn.y=2.4;
- pic_btn.label="图像类";
- pic_btn.x=2.4;
- this.addChild(pic_btn);
- other_btn.label="其他类";
- other_btn.x=106.4;
- this.addChild(other_btn);
- swf_btn.label="动画类";
- swf_btn.x=212.4;
- this.addChild(swf_btn);
- bigmc.width=350;
- bigmc.height=250;
- bigmc.x=125;
- bigmc.y=60;
- this.addChild(bigmc);
- smallmc1.width=smallmc2.width=smallmc3.width=smallmc4.width=smallmc5.width=smallmc_w;
- smallmc1.height=smallmc2.height=smallmc3.height=smallmc4.height=smallmc5.height=smallmc_h;
- smallmc1.y=smallmc2.y=smallmc3.y=smallmc4.y=smallmc5.y=list_y;
- smallmc1.x=list_x;
- smallmc2.x=smallmc1.x+smallmc_w+list_margin;
- smallmc3.x=smallmc2.x+smallmc_w+list_margin;
- smallmc4.x=smallmc3.x+smallmc_w+list_margin;
- smallmc5.x=smallmc4.x+smallmc_w+list_margin;
- //显示为手型链接
- smallmc1.buttonMode=true;
- smallmc2.buttonMode=true;
- smallmc3.buttonMode=true;
- smallmc4.buttonMode=true;
- smallmc5.buttonMode=true;
- this.addChild(smallmc1);
- this.addChild(smallmc2);
- this.addChild(smallmc3);
- this.addChild(smallmc4);
- this.addChild(smallmc5);
- loadclass("pic");
- }
- //函数功能:释放空闲内存资源
- function UnloadAll() {
- bigmc.unload();
- smallmc1.unload();
- smallmc2.unload();
- smallmc3.unload();
- smallmc4.unload();
- smallmc5.unload();
- }
热门文章推荐
- [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示例
请稍候...