Jump to content


Photo

reading from a file using Files object


  • Please log in to reply
2 replies to this topic

#1 mitya777

mitya777

    FireStarter

  • Members
  • PipPip
  • 28 posts

Posted 22 February 2012 - 09:01 AM

Hi guys, I am trying to read a file from a Fireworks Panel.

I have the following javascript code:

var readFile = function(fileUrl){

var fileReference = Files.open(fileUrl, false); //call with false to read instead of write
var lines = [];
var line = "";

while(fileReference !== null){
console.log("reading line: ", fileReference); //this returns "reading line: {}"
line = fileReference.readline();
console.log("finished reading line"); //this never prints
lines.push(line);
}

fileReference.close();
}

From the panel I call the function like this:

MMExecute('fwiolib.readFile("'+configUrl+'");');

(fwiolib is an object I previously loaded into memory which gives me access to a bunch of these IO functions. The text file is just a single line of text.)

As you can see from the commented console.log output in the above code the execution never makes it past the fileReference.readLine() call.

What am I missing?

Thank you for your help.

#2 mitya777

mitya777

    FireStarter

  • Members
  • PipPip
  • 28 posts

Posted 22 February 2012 - 02:56 PM

Not sure why the code formatting didn't come out... sorry about that.

#3 mitya777

mitya777

    FireStarter

  • Members
  • PipPip
  • 28 posts

Posted 22 February 2012 - 03:39 PM

I'm embarrassed to say that the error was one of spelling :( although one facilitated by the fact that the other read method is called readLineUTF8 with a capitol "L", as opposed to readline() small "l".