cc952a1d727e0376a640003e6d5e324e6ff48fd8.svn-base 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.act {
  2. /*
  3. 文件名称:ckplayer加载xml文件的类
  4. 作用:加载指定的xml文件并返回对象,是用来做精彩视频推荐使用的
  5. 版本:1.0
  6. 制作:捻灯
  7. 开始时间:2014-3-26
  8. */
  9. import flash.net.URLLoader;
  10. import flash.net.URLRequest;
  11. import flash.events.Event;
  12. import flash.events.IOErrorEvent;
  13. import flash.net.URLVariables;
  14. import flash.net.URLRequestMethod;
  15. public class loadXml {
  16. private var f:Function;//加载成功或失败都返回该函数
  17. private var l:URLLoader=null;
  18. public function loadXml(m:String,c:Function):void {
  19. f=c;
  20. l=new URLLoader();
  21. l.load(new URLRequest(m));
  22. l.addEventListener(Event.COMPLETE,com);
  23. l.addEventListener(IOErrorEvent.IO_ERROR,err);
  24. }
  25. private function remove():void{
  26. l.removeEventListener(Event.COMPLETE, com);
  27. l.removeEventListener(IOErrorEvent.IO_ERROR, err);
  28. }
  29. private function com(event:Event):void{
  30. var xml:XML=new XML(event.currentTarget.data);
  31. if(xml){
  32. analysis(xml);
  33. }
  34. else{
  35. f(null,false);
  36. }
  37. remove();
  38. }
  39. private function analysis(xml:XML):void{
  40. var obj:Object={};
  41. var r:XMLList = xml.children();
  42. var r2:XMLList=xml.relatedlist.children();
  43. var m:String="";
  44. var a:Array=[];
  45. //trace(r);
  46. for each(var k in r){
  47. m=k.name();
  48. obj[m]=k;
  49. if(m=="relatedlist"){
  50. obj[m]=[];
  51. for each(var k2 in r2){
  52. a=[k2.img,k2.url,k2.title]
  53. obj[m].push(a);
  54. }
  55. }
  56. }
  57. f(obj);
  58. }
  59. private function err(event:IOErrorEvent) {
  60. f({},false);
  61. remove();
  62. }
  63. }
  64. }