title: Create a docx using FZIP in Actionscript 3 - Adobe AIR
body: <p>Hello
  I will try my best to explain my problem and I really hope someone can figure out what could be wrong.</p>
  
  <p><strong>Situation:</strong></p>
  
  <p>Using the office open XML format by microsoft I was able to create the files needed for a clean Word document. These files are all XML files. What I do is write the XML content to a different bytearray for each file.</p>
  
  <p>I then add the bytearray's to the FZIP library (http://codeazur.com.br/lab/fzip/) and create a docx file using the following code:</p>
  
  <pre><code>var zip:FZip = new FZip();
  zip.addFile("/_rels/", null, false);
          zip.addFile("/docProps/", null, false);
          zip.addFile("/word/", null, false);
  
          zip.addFile("[Content_Types].xml", bytContentType, false);
          zip.addFile("/docProps/app.xml", bytApp, false);
          zip.addFile("/docProps/core.xml", bytCore, false);
          zip.addFile("/word/document.xml", bytDocument, false);
          zip.addFile("/word/fontTable.xml", bytFontTable, false);
          zip.addFile("/word/settings.xml", bytSettings, false);
          zip.addFile("/word/webSettings.xml", bytWebSettings, false);
          zip.addFile("/_rels/.rels", bytRels, false);
  
          var file:File = File.documentsDirectory;
          file = file.resolvePath(folder + ".docx");
          var stream:FileStream = new FileStream();
          stream.open(file, FileMode.WRITE);
          zip.serialize(stream);
          stream.close();
  </code></pre>
  
  <p>Ok this creates a new docx file in my documents. If I rename the .docx to .zip and unzip it it will follow the exact structure needed for Word documents (example: <a href="http://dl.dropbox.com/u/5490354/Screen%20shot%202011-05-08%20at%2019.40.10.png" rel="nofollow">http://dl.dropbox.com/u/5490354/Screen%20shot%202011-05-08%20at%2019.40.10.png</a>)
  In this example "Untitled Document" was originally "Untitled document.docx" (then renamed to .zip and extracted)</p>
  
  <p>So you can see everything works fine <strong>untill...</strong> you try to open the "Untitled document.docx" in Word. It will say the file is corrupt.</p>
  
  <p><strong>WHAT DOES WORK HOWEVER...</strong> 
  After extracting the docx file (like in screenshot) when you select all the files/folders inside the Untitled Document folder and ZIP those, then rename ZIP file to docx (see result: <a href="http://dl.dropbox.com/u/5490354/Screen%20shot%202011-05-08%20at%2019.44.18.png" rel="nofollow">http://dl.dropbox.com/u/5490354/Screen%20shot%202011-05-08%20at%2019.44.18.png</a>) it works fine in Word and word reads the file correctly. NOTE: If you try to zip and rename the Untitled Document folder again it will become corrupt again as well.</p>
  
  <p><strong>So my question</strong>
  I hope the description was clear and now I am hoping for someone who knows what could be the problem that the word file is corrupt when zipped using FZIP in actionscript 3 but works fine when you ZIP the files after extracting your corrupt file.</p>
  
  <p>Thanks</p>