2011-08-15 54 views
2

我在這裏有一個問題,解壓縮我在combobox.i中的.zip文件,選擇1 .zip文件,然後選擇特定的.zip文件按鈕應解壓縮並將內容放入另一個組合框中。有人可以幫我在這裏?如何在ActionScript中使用base64編碼解壓縮文件?

這裏是一個代碼:

// ActionScript file 
    import flash.display.*; 
    import flash.events.*; 
    import flash.utils.ByteArray; 
    import com.Base64; 
    import mx.controls.Alert; 

    [Bindable] private var sfile:FileReference; 
    [Bindable] private var zipdataProvdr:ArrayCollection = new ArrayCollection([{label:  "test", file: "test"},{label: "elm34001", file: "elm34001"}, {label: "elm34003", file: "elm34003"}, {label: "elm34005", file: "elm34005"}, {label: "elm34009", file: "elm34009"},{label: "elm34011", file: "elm34011"}, {label: "elm34013", file: "elm34013"}]); 
     //private var zip:FZip; 
     //private var flag:Boolean; 


     private function init(event:Event):void 
     { 
     var file:ByteArray = new ByteArray(); 
     file = "test.zip"; 
     var encode:String = Base64.encodeByteArray(file); 
     Alert.show("Encoded file is " + encode); 
     for (var i:int = 0; i < zipdataProvdr.length; i++) 
     { 
     file = zipdataProvdr[i]; 
     Alert.show("file is " + file); 
     } 
     //var encoded:String = Base64.encodeByteArray(file); 
     //Alert.show("encoded file is " + encoded.toString()); 


     } 
+0

你能展示一些你目前在做什麼的代碼嗎?你卡在哪裏? –

+0

上面是代碼,我不能將一個zip文件分配給bytearray變量? – kanak

回答

0

我不知道你能。沒有必要重新發明輪子,嘗試使用這樣一個zip庫而不是:​​

+0

可以請你發表一個代碼嗎? – kanak

+0

號您是否點擊鏈接?那裏有代碼。 –

+0

感謝您的幫助公民康恩! – kanak

1

我用Nochump lib解壓縮文件。以下是代碼:

<?xml version="1.0" encoding="utf-8"?> 
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"   layout="absolute"> 
    <mx:Script> 
     <![CDATA[ 
      import flash.net.URLStream; 
      import flash.net.URLRequest; 
      import mx.controls.Alert; 
      import mx.collections.ArrayCollection; 
      import flash.events.Event; 
      import flash.events.ErrorEvent; 
      import flash.events.ProgressEvent; 
      import nochump.util.zip.ZipFile; 


      [Bindable] private var _files:Array = ["/MyMapFolder/elm34001.zip", "/MyMapFolder/elm34003.zip", "/MyMapFolder/elm34005.zip", "/MyMapFolder/elm34009.zip", "/MyMapFolder/elm34011.zip", "/MyMapFolder/elm34013.zip"]; 
      private var zpfls:ZipFile; 
      [Bindable] private var arr:Array; 
      private var arrcoll:ArrayCollection; 

      private function loadZipFile():void { 
      currentState = "loading"; 
      var urlStream:URLStream = new URLStream(); 
      loadProgress.source = urlStream; 
      urlStream.addEventListener(Event.COMPLETE,completeHandler); 
      urlStream.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); 
       //urlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler); 
      urlStream.load(new URLRequest(String(cbFiles.selectedItem))); 
      //Alert.show("Testing........" + urlStream.endian); 
      //Alert.show("Testing........" + urlStream.objectEncoding); 
      //Alert.show("Testing........" + urlStream); 
     } 

     private function completeHandler(event:Event):void 
     { 
      var data:URLStream = URLStream(event.target); 
      arr = new Array(); 
      //Alert.show("***Length of file is " + data.bytesAvailable); 
      zpfls = new ZipFile(data); 
      arr = new Array(zpfls.entries[1]); 
      Alert.show("Show only Shape File: " + arr); 
     } 

     private function errorHandler(event:ErrorEvent):void { 
      currentState = "error"; 
      errorLabel.text = event.text; 
     } 

    ]]> 
    </mx:Script> 
    <mx:states> 
     <mx:State name="loading"> 
      <mx:AddChild relativeTo="{this}" position="lastChild"> 
      <mx:ProgressBar id="loadProgress" width="100%" /> 
      </mx:AddChild>   
     </mx:State> 
     <mx:State name="error"> 
     <mx:AddChild relativeTo="{this}" position="lastChild"> 
      <mx:Label id="errorLabel" /> 
     </mx:AddChild> 
     </mx:State> 
    </mx:states> 

    <mx:Label text="Select a zip file and click &quot;Load&quot;." x="67" y="10"/> 
    <mx:ComboBox id="cbFiles" dataProvider="{_files}" width="300" x="10" y="36"/> 
    <mx:Button label="Load" click="loadZipFile()" x="333" y="36"/> 
    <mx:ComboBox x="394" y="36" id="cbobxs" dataProvider="{arr}" width="169">   </mx:ComboBox> 

     </mx:Application> 
相關問題