开发者

how to unzip the files using base64 encoding in actionscript?

I have a issue here with unzipping the .zip files that i have in combobox.i select 1 .zip file and after selecting the particular .zip开发者_JAVA技巧 file Button should unzip it and put the contents in another combobox.Can someone help me here?

here is a code:

    // 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());


       }


I used Nochump lib to unzip the files. Following is the code:

    <?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>


I'm not sure you can. No need to reinvent the wheel though, try using a zip library like this one instead: http://nochump.com/blog/archives/15

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜