これが実際の例です。短くするために、私は多くの無名関数を使用しました。
package {
import deng.fzip.FZip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import flash.utils.ByteArray;
public class ZipTest extends Sprite {
private var imageRefList : FileReferenceList = new FileReferenceList();
private var saveRef : FileReference = new FileReference();
private var zipName : String = "someName.zip";
public function ZipTest() {
var someButton : Sprite = new Sprite();
with(someButton.graphics) {
beginFill(0x00ff00);
drawRect(0, 0, 50, 50);
endFill();
}
addChild(someButton).addEventListener(MouseEvent.CLICK, function(event : MouseEvent) : void {
var saveZip : Function = function(zip : FZip) : void {
var out : ByteArray = new ByteArray();
zip.serialize(out);
saveRef.addEventListener(Event.COMPLETE, function(e : Event) : void {
trace("done");
});
saveRef.save(out, zipName);
};
imageRefList.addEventListener(Event.SELECT, function(e : Event) : void {
var zip : FZip = new FZip();
var count : int = imageRefList.fileList.length;
for each (var image: FileReference in imageRefList.fileList) {
image.addEventListener(Event.COMPLETE, function(e : Event) : void {
var img : FileReference = FileReference(e.target);
trace(count + " loaded... " + img.name);
zip.addFile(img.name, img.data);
count--;
if (count == 0) saveZip(zip);
});
trace("load: " + image.name);
image.load();
}
});
imageRefList.browse();
});
}
}
}