Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
File API | 79

</head>
<body onload="doLoad( )">

<textarea id="txtNote"></textarea>
<input id="btnSave" type="button" value="Save" />

</body>
</html>

Synchronously Reading Text from a File


Problem


You want to read the contents of a small text file into your
application.


Solution


Use the various file APIs provided by Adobe AIR to locate,
open, and read text files.


Discussion


Small files that contain text content can be read using the
FileStream.open( )method. This method opens a file syn-
chronously for reading. Synchronous access requires less
code, but also blocks any additional user input until the data
has been read. When using asynchronous access, additional
user input is not blocked, but event handlers must be regis-
tered, which results in more code overhead.


TIP
While accessing XML files as text is possible, the result of
this approach is a document object that can’t be readily
manipulated. Accessing an XML file for use as a data
source, is often more easily handled usingXMLHttpRequest
or wrapper functionality offered by most JavaScript
libraries.
Free download pdf