2 Replies Latest reply on Mar 29, 2008 10:51 AM by tony0000000

    how do i asynchronously write binary files?

    tony0000000 Level 1
      Hi

      I'm sure I'm missing something obvious here but I cant see what's wrong with my code. I'm trying to save a file using asynchronous methods but for some reason the function onCompleteFunc is not being called. Any ideas what I'm doing wrong?

      function testSaving(fileObj, binaryData, onSuccessFunc, onErrorFunc){
      var onCompleteFunc = function(event){
      try {
      stream.writeBytes(binaryData, 0, binaryData.length);
      }
      catch (fileError) {
      onIoErrorFunc();
      }
      stream.close();
      onSuccessFunc();
      }

      var onIoErrorFunc = function(event){
      stream.close();
      onErrorFunc(event);
      }

      var stream = new air.FileStream();
      stream.addEventListener(air.Event.COMPLETE, onCompleteFunc);
      stream.addEventListener(air.IOErrorEvent.IO_ERROR, onIoErrorFunc);
      stream.openAsync(fileObj, air.FileMode.WRITE);

      }