1

ユーザーとの対話後にbmp、xml、およびテキストドキュメントを含むフォルダーを作成するAirアプリを作成しました。自動である必要がある最終的なzipを作成することを除いて、すべてが機能します。

私はこれに対する解決策を探していましたが、それを見つけることができません。たぶん私はそれを見ていません、もしそうなら、誰かが私に見せてくれませんか。

これに関する私の最初の投稿はここにあります--- Airas3flashで多くのファイルを圧縮します


私が見つけた最も近いものはこれでした--- fzipを使用してフォルダをzipします しかし、何らかの理由で私のコメントが削除されました---

私はこれが好き。それは私が自分の問題の実用的な解決策に到達した最も近いものです。そうは言っても、私はこれをテストしましたが、そのままでうまく機能します。このスクリプトは、対話なしで実行するようにモデレートできますか?私が書いたプログラムのためにそれを必要としています。どんな援助も歓迎です........それは私が必要とするもののようなものを持っていないので、アドビの参照を私に指摘することを除いて。(私が見たり見つけたりできること)

だから今、私はコミュニティに再質問しています。

何らかの理由で、手動選択と手動保存で機能しますが、aotonomuslyでは機能しません。別のフルページのスクリプトが必要な場合でも、これには回避策が必要です。

================================================== ==================更新:これを締めくくるために、私はついに解決策を手に入れました。ここで見つけることができます。「zipファイルの内容にデータがありません」。私の問題が将来誰かを助けることができることを願っています。

4

1 に答える 1

2

as3commonszipライブラリを使用してみてください。

http://www.as3commons.org/as3-commons-zip/index.html

これを行うには、ディレクトリをロードし、そのすべてのコンテンツをループして、各アセットをロードする必要があります。

このコードスニペットには、それを処理するためのバルクローダーが含まれています。

警告

私はこのコードのほとんどを、私が似たようなことをしているプロジェクトから引き出しましたが、そのままではテストしていません。構文エラーがあるかもしれません!

private var zip:Zip;

zip = new Zip();


zip.addEventListener(IOErrorEvent.IO_ERROR, this.createNewZip); //creates a new zip
zip.addEventListener(Event.COMPLETE, handleZipLoaded); //loads the current zip, this is not shown here
zip.load(new URLRequest(File.applicationStorageDirectory.resolvePath("myZip.zip").url)); //path to your zip file

新しいzipファイルを作成する方法

private function createNewZip(e:IOErrorEvent):void{

    trace("no zip");

    var stream:FileStream = new FileStream();
    stream.open(File.applicationStorageDirectory.resolvePath("myZip.zip"), FileMode.WRITE);

    zip.serialize(stream);
    stream.close();

}   

これを使用して、ディレクトリ内のすべてのアイテムをzipファイルに追加できます。

private function addDirToZip():void{

    var f:File = File.resolvePath("Your Dir");
    //this will be called when your directory listing has loaded
    f.addEventListener(FileListEvent.DIRECTORY_LISTING, handleDirLoaded);
    //you can also get the dir listing inline and not use a listener
    //doing it async will prevent ui lock
    f.getDirectoryListingAsync();

}

次に、すべてのファイルをロードする必要があります

protected function handleDirLoaded(e:FileListEvent):void{
    loadExternal = new Vector.<File>; //vector used to keep a handle on all files
    e.target.removeEventListener(FileListEvent.DIRECTORY_LISTING, handleDirLoaded);
    for(var i:int = 0 ; i < files.length ; i++){
        var f:File = files[i] as File;
        if(f.extension == "File Types you want"){  //you can do some file type checking here
              loadExternal.push(f);
        }

    }
   //start loading in the files
   loadFile();
}

これはloadExternalベクトルを通過し、すべてのファイルをロードします

private function loadFile():void{
    currentFile = loadExternal.shift(); //returns the first item off the array

    //load the file
   var l:Loader = new Loader();
   l.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaded);
   l.load(new URLRequest(currentFile.url));

}

各アイテムが読み込まれると、zipに追加するために保存できます

private function handleLoaded(e:Event):void{

    var l:Loader = e.target.loader as Loader;
    l.contentLoaderInfo.removeEventListener(Event.COMPLETE, handleLoaded);

    //storing everything in a dictionary 
    assets[currentFile.name] = l.content;

   //if we still have items to load go and do it all again

   if(loadExternal.length != 0){
        loadFile();
   } else {
       //now all files are loaded so lets add them to the zip
       addAssetsToZip();
   }

}

これは、ロードされたすべてのファイルが実際にzipに入れられ、保存される場所です。

private funcion addAssetsToZip():void{

   for(var fileName:String in assets){
        var ba:ByteArray = new ByteArray(); //going to write this to the zip
        //make an object that holds the data and filename
        var data:Object = {};
        data.name = fileName;
        data.content = assets[fileName];
        ba.writeObject(data);
        //write this file to the zip
        zip.addFile(key, ba, false);
    }

    //and finally save everything out
    zip.close();
    var stream:FileStream = new FileStream();
    stream.open(File.applicationStorageDirectory.resolvePath("myZip.zip"), FileMode.WRITE);
    zip.serialize(stream);
    stream.close();
}
于 2012-09-09T19:18:42.273 に答える