开发者

Using Fzip lib under Adobe Air App

I'm currently working on a project 开发者_如何学Pythonfor Adobe Air (1.5.3) and I need to unzip a file, copy some of its contents to another file.

Then I saw people talking about the Fzip (http://codeazur.com.br/lab/fzip) lib. The problem is that I don't know how to "import" or use this library with Javascript and Adobe Air, since Javascript doesn't have the import directive.

How can I manage to do that ?


I posted a demo of how to use FZip with Adobe Air and Javascript. I hope it hopes clear things up for you.

In short you need to pull the SWF file out of the compiled SWC (when applicable) and access the class.

The demo is pretty simple and really just a proof of concept but you should be able to extend it easily.

http://www.drybydesign.com/2010/05/12/adobe-air-fzip-without-flex/

-Ari


Ari's example is pretty good, and it got me started but he left out some pretty crucial stuff--like writing the uncompressed files back to the disk. And the zip file does not have to be hosted remotely--the thing about AIR is that it runs like a local Application...here is an example that build on the good start Ari gave us. (I am using HTML5 just to be cool and hip and modern! :)-

<!DOCTYPE HTML>
<html> 
 <head>
    <title>Test Fzip</title> 
<script type="application/x-shockwave-flash" src="scripts/fzip.swf"></script>
<script type="text/javascript" src="scripts/AIRAliases.js"></script>
<script type="text/javascript" src="scripts/AIRIntrospector.js"></script>
<script type="text/javascript" src="scripts/jquery-1.4.2.js"></script>
<script type="text/javascript">
        var fzip;
        if (window.runtime) {
            if (!fzip) 
                fzip = {};
                fzip.FZip = window.runtime.deng.fzip.FZip;
                fzip.FZipFile = window.runtime.deng.fzip.FZipFile;
        }
        var file = air.File.documentsDirectory.resolvePath("test.zip");
        //file.url
        var zip = new fzip.FZip;
        zip.addEventListener(air.Event.OPEN, onopen);
        zip.addEventListener(air.Event.COMPLETE, oncomplete);
        zip.load(new air.URLRequest(file.url.toString()));

        function oncomplete(event) {
            var count = zip.getFileCount();
                        alert(count);

            for ( var idx = 0; idx < count; idx++)
            {
                var zfile = zip.getFileAt(idx);
                // alert(zfile.filename);
                var uzfile = air.File.applicationStorageDirectory.resolvePath(zfile.filename);
                var stream = new air.FileStream();
                stream.open( uzfile, air.FileMode.WRITE );
                stream.writeBytes( zfile.content,0, zfile.content.length );
                stream.close();
            }

        }

        function onopen(event) {
            alert("file is opened");
        }
</script>
 </head> 
    <body> 


    </body> 
</html>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜