0

Using phonegap 2.9.0, using this callback to read file:

    fBrowse.params.on_file_select = function(file){     // file: FileEntry  
        try{
            var reader = new FileReader();
            jsIQ.msg('loading game!..');
            reader.onload = function(evt) {
                // success
                var game = null;
                // remove garbage from string
            jsIQ.msg('loading game!3..' + arguments.length);
            jsIQ.msg('loading game!3/2: ' + evt.target.result);
            //jsIQ.msg('data: ' + evt.target.result, 2);
                var s = $.trim(B64.decode(evt.target.result));
            jsIQ.msg('loading game!4..');
                s = s.substr(0, s.indexOf('}')+ 1);
            jsIQ.msg('loading game!5..');
                game = JSON.parse( s );
                if (game != null) {
                    // success!
                    $('#fBrowse').hide();
                    jsIQ.msg('Load game success', 2);
                    jsIQ.triggerEvent('heart_game_loaded', {data: game});
                }
            };
            reader.onerror = function(){
                alert('error reading file');
            };
            jsIQ.msg('loading game!2..');
            file.file(function(f){
                reader.readAsText(f);
            }, function(){
                alert('Error opening file');
            });
        } catch (e){
            jsIQ.msg('loadgame err: ' + e.message, 2);
            alert('Внутренняя ошибка');
        }
        //return true;
    };

and i see this log file contents:

...

[-] 17:1:26.257 Load game file: /mnt/sdcard/heartofice/heartofice2.savegame

[-] 17:1:26.260 loading game!..

[-] 17:1:26.262 loading game!2..

[-] 17:1:26.270 loading game!3..1

this means, the line with

evt.target.result

is falling with error WITHOUT any notices! "evt" have been passed to success read callback, but i can't use it??

This happens on real android device (4.0.3)

Tried to use "reader.result" from onload callback, but got same behavior!

How to solve this?

3
  • And i tried to use onloadend event - same result...
    – Jumangee
    Sep 11, 2013 at 13:49
  • Do you get any errors in logcat? logcat would surface any of the JavaScript console errors as well. You could try doing something like console.log(JSON.stringify(evt)) to see if the evt object looks like what you expect.
    – MBillau
    Sep 11, 2013 at 15:02
  • jsIQ.msg do the same log as console.log, but in external file. But any kind of use "evt" breaks this function: typeof(evt), if (!evt).
    – Jumangee
    Sep 11, 2013 at 16:55

1 Answer 1

0

I found a solution:

jsIQ.msg uses a FileWriter to put data to log

So, when I "got a file", I messaged it to log - this breaks a link to "readed file", and it becomes obsolete.

As so, never use combination:

  1. get file#1 for read
  2. get file#2 for write, write
  3. read file#1

Reasons of this behavior are unknown...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.