_urlLoader=new URLLoader(); _urlLoader.dataFormat=URLLoaderDataFormat.BINARY; _urlLoader.addEventListener(Event.COMPLETE,parseFunc); _urlLoader.addEventListener(ProgressEvent.PROGRESS,progressHandle); _urlLoader.addEventListener(IOErrorEvent.IO_ERROR,ioHandler); _urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler) var _path:String=WarModel.getInstance().imgIp+StringUtil.substitute(URLConst.STATIC_FILES_PATH,WarModel.getInstance().lang,WarModel.getInstance().v1); _urlLoader.load(new URLRequest(_path)); private function parseFunc(evt:Event):void { CONFIG::debug { Logger.debug("加载完成,开始解析",false,this); } var _by:ByteArray=evt.target.data; _by.uncompress(); var _pos:int=_by.readInt(); var _keyLen:int=_by.readInt(); var _byData:ByteArray=new ByteArray(); if(_pos>0) _by.readBytes(_byData,0,_pos); var _key:String=_by.readUTFBytes(_keyLen); _by.readBytes(_byData,_pos,0); WarModel.getInstance().key=_key; CONFIG::debug { Logger.debug("取Key:"+_key+"|"+_pos+"|"+_keyLen,false,this); } var _zipFile:ZipFile=new ZipFile(_byData); var _zipEntryArr:Array=_zipFile.entries; var _len:int=_zipEntryArr.length; _parseQueue=[]; for(var i:int=0;i<_len;i++) { var _entry:ZipEntry=_zipEntryArr[i]; if(!_entry.isDirectory()) { var _entryName:String=_entry.name; var _index:int=_entryName.lastIndexOf("/"); var _fileName:String; if(_index>=0) { _fileName=_entryName.substring(_index+1,_entryName.length); } else { _fileName=_entryName; } CONFIG::debug { Logger.debug("File:"+_fileName,false,this); } var _resultBy:ByteArray=_zipFile.getInput(_entry); var _resultStr:String; var _result:Object; if(_fileName.indexOf(".swf")==-1) { _resultStr=_resultBy.readMultiByte(_resultBy.bytesAvailable,"utf-8"); _result=_resultStr; } else _result=_resultBy; if(_fileName=="Labor.xml") { parseLaborsInfo(_result.toString()); } private function parseLaborsInfo(result:String):void { var _xml:XML=XML(result); var _loborList:XMLList=_xml.Labor; var _allArr:Array = []; for each(var lobor:XML in _loborList) { var _loborVO:StaticLoborVO = new StaticLoborVO(); _loborVO.id = lobor[0].@id; _loborVO.name = lobor[0].laborName; _loborVO.image = StringUtil.substitute(lobor[0].laborImage,WarModel.getInstance().imgIp); _loborVO.level = lobor[0].level; _loborVO.silver = lobor[0].silver; _loborVO.gold = lobor[0].gold; _loborVO.time = lobor[0].time; _loborVO.effic = lobor[0].effic; _loborVO.desc = lobor[0].desc; _allArr.push(_loborVO); } WarModel.getInstance().staticLoborDict = _allArr; CONFIG::debug { Logger.debug("解析Labor.xml",false,this); } checkOver(); }
这里为大家介绍一种flex解析zip文件的方法,这种方法是面对已经加密的文件的一种方法, 大家可以看看,具体对你有没有用处,我就不大清楚了!