6 Replies Latest reply on Sep 23, 2009 10:52 AM by seaneyefi

    air.Event.COMPLETE not firing

    seaneyefi Level 1

      Using AIR 1.5.2 in a HTML based application, it looks like my air.Event.COMPLETE listener is not firing. Here's what my code looks like:

               var file = air.File.applicationStorageDirectory;
              file = file.resolvePath("Log.log");
              this.fileStream = new air.FileStream();
              this.fileStream.addEventListener(air.Event.COMPLETE, indicateReady);
              this.fileStream.addEventListener(air.IOErrorEvent.IO_ERROR, indicateError);
              this.fileStream.openAsync(file, air.FileMode.APPEND);


      All I'm doing is trying to open an asynchronous stream to a log file and get some notification of when the stream is ready to be written to.


      Is there any way of listening for all the events fired by the fileStream variable?


      Anyone any ideas on what I might be doing wrong here?





        • 1. Re: air.Event.COMPLETE not firing

          Hello seaneyefi,


          You can monitorize logs if you checking with a timer the modificationdate, like this: "yourFile.modificationDate.getTime();"


          Or you can use this of Mike Chambes:




          Anyway, more later, you probably find my problem if want to read in real time the content of the file (look my post)


          http://forums.adobe.com/thread/495445;jsessionid=E6437369E7A711508882D0D99A463212.node0?ts tart=0


          Hope I can help you in the first step, but in the second I need help too.

          • 2. Re: air.Event.COMPLETE not firing
            seaneyefi Level 1

            Thanks for the link Ehome, but I don't really need to monitor log files to the extent you do as you've outlined in your forums post.


            One question for you though: Do you use an event handler to notify you when the "target" file has opened asynchronously? If you do, and this is working for you, I'd appreciate it if you could post your code.





            • 3. Re: air.Event.COMPLETE not firing
              Ehome.Arkham Level 1

              Wrong post

              • 4. Re: air.Event.COMPLETE not firing
                Ehome.Arkham Level 1

                Yes, I use a listener for many events for openasync and look this partial code:


                _stream = new FileStream;
                _stream.openAsync(_fileZ, FileMode.READ)
                _stream.addEventListener(IOErrorEvent.IO_ERROR, _streamErrorTimer);
                _stream.addEventListener(Event.COMPLETE, _readNewBytes);
                Then you need create two functions after that, _streamErrorTimer (or called as you like) and _readNewBytes. Depends what you want to do with the events, put your own code in this two new functions.
                Try to put the openasync until the listeners.
                Thx for reply and if need something and I can help you, contact again.
                • 5. Sean
                  seaneyefi Level 1

                  Unfortunately, the COMPLETE event doesn't fire when you open the file in APPEND mode. This is what my code looks like:


                  // now open a stream to the new file

                  this.fileStream = new air.FileStream();

                  this.fileStream.addEventListener(air.Event.COMPLETE, function() {

                  // indicate that the stream is now appendable


                  this.fileStream.addEventListener(air.IOErrorEvent.IO_ERROR, function(){

                  // deal with error here.


                  this.fileStream.openAsync(file, air.FileMode.APPEND);


                  If I change the last line of that code to look like this:


                  this.fileStream.openAsync(file, air.FileMode.READ);


                  ... my complete callback is invoked without any problems. Looks like it won't fire for APPEND though.


                  Anyone any ideas on why this is the case? Should I make the assumption that the file is always append-able, and only indicate that it is not appendable when I get an error after trying to write bytes to this stream?



                  • 6. air.Event.COMPLETE not firing
                    seaneyefi Level 1

                    Tried using UPDATE instead of APPEND and the COMPLETE event fires. But, using update doesn't allow me append to the file


                    Any ideas?