Online/Offline | 107
if( file.exists )
{
var fileStream = new air.FileStream( );
fileStream.open( file, air.FileMode.READ );
data =
fileStream.readMultiByte( fileStream.bytesAvailable,
air.File.systemCharset );
fileStream.close( );
}
else
{
// read the data via XMLHttpRequest and write that
// data to the file system
}
Here is the complete example:
<html>
<head>
<title>Caching Assets for Offline Use</title>
<script src="AIRAliases.js"></script>
<script>
var file =
air.File.applicationStorageDirectory.resolve("data.xml");
function onLoad( )
{
if( file.exists )
{
var fileStream = new air.FileStream( );
fileStream.open( file, air.FileMode.READ );
document.getElementById( "dataText" ).value =
fileStream.readMultiByte(
fileStream.bytesAvailable,
air.File.systemCharset );
fileStream.close( );
}
else
{
var xml = new XMLHttpRequest( );
xml.open( "GET",
"http://www.foo.com/data.xml", true );
xml.onreadystatechange = function( )
{