xwielder
01-15-2008, 07:04 PM
Suppose I have the following code:
var something:String = "";
myButton.addEventListener(MouseEvent.CLICK, iGotClicked);
function iGotClicked (event:MouseEvent)
{
something = "Happy Day";
writeLastLocation ();
}
// WRITE
var writeFileStream:FileStream = new FileStream();
function writeLastLocation ()
{
var writeFile:File = File.applicationStorageDirectory;
var wrietFileString:String = (writeFile.nativePath + "\\FileLastLocation.txt");
writeFile = writeFile.resolvePath(wrietFileString);
writeFileStream.addEventListener(Event.COMPLETE, completedWriteLastLocation);
writeFileStream.openAsync (writeFile, FileMode.WRITE);
}
function completedWriteLastLocation(event:Event):void
{
trace("Hello");
writeFileStream.writeUTFBytes (something);
writeFileStream.close ();
writeFileStream.removeEventListener(Event.COMPLETE , completedWriteLastLocation);
readLastLocation ();
}
// READ
var readString:String = "";
var readFileStream:FileStream = new FileStream();
function readLastLocation ()
{
var readFile:File = File.applicationStorageDirectory;
var readFileString:String = (readFile.nativePath + "\\FileLastLocation.txt");
readFile = readFile.resolvePath(readFileString);
readFileStream.addEventListener(Event.COMPLETE, completedReadLastLocation);
readFileStream.openAsync(readFile, FileMode.READ);
}
function completedReadLastLocation(event:Event):void
{
trace("World");
readString = readFileStream.readMultiByte(readFileStream.bytesA vailable, "iso-8859-1");
readFileStream.close ();
readFileStream.removeEventListener(Event.COMPLETE, completedReadLastLocation);
trace("readString = " + readString);
}
According to Adobe's documents: http://livedocs.adobe.com/labs/air/1/devappsflash/help.html?content=Filesystem_32.html
The above code should write a file, then read it back.
What's odd is I never get the "Hello" trace. Here's what's even more strange...
If I call the readLastLocation() function within iGotClicked (example:)
function iGotClicked (event:MouseEvent)
{
something = "Happy Day";
readLastLocation ();
}
I get the "World" trace.
So for some reason, writeFileStream.addEventListener(Event.COMPLETE, completedWriteLastLocation); is never getting fired, but readFileStream.addEventListener(Event.COMPLETE, completedReadLastLocation); is.
Any ideas on what I'm doing wrong?
NOTE:
There were a few times when I removed the COMPLETE eventListeners and forced the subfunctions, but I kept getting errors that the file was open and there was a sharing violation blah blah blah. Even though I .close()'d the filestream.
var something:String = "";
myButton.addEventListener(MouseEvent.CLICK, iGotClicked);
function iGotClicked (event:MouseEvent)
{
something = "Happy Day";
writeLastLocation ();
}
// WRITE
var writeFileStream:FileStream = new FileStream();
function writeLastLocation ()
{
var writeFile:File = File.applicationStorageDirectory;
var wrietFileString:String = (writeFile.nativePath + "\\FileLastLocation.txt");
writeFile = writeFile.resolvePath(wrietFileString);
writeFileStream.addEventListener(Event.COMPLETE, completedWriteLastLocation);
writeFileStream.openAsync (writeFile, FileMode.WRITE);
}
function completedWriteLastLocation(event:Event):void
{
trace("Hello");
writeFileStream.writeUTFBytes (something);
writeFileStream.close ();
writeFileStream.removeEventListener(Event.COMPLETE , completedWriteLastLocation);
readLastLocation ();
}
// READ
var readString:String = "";
var readFileStream:FileStream = new FileStream();
function readLastLocation ()
{
var readFile:File = File.applicationStorageDirectory;
var readFileString:String = (readFile.nativePath + "\\FileLastLocation.txt");
readFile = readFile.resolvePath(readFileString);
readFileStream.addEventListener(Event.COMPLETE, completedReadLastLocation);
readFileStream.openAsync(readFile, FileMode.READ);
}
function completedReadLastLocation(event:Event):void
{
trace("World");
readString = readFileStream.readMultiByte(readFileStream.bytesA vailable, "iso-8859-1");
readFileStream.close ();
readFileStream.removeEventListener(Event.COMPLETE, completedReadLastLocation);
trace("readString = " + readString);
}
According to Adobe's documents: http://livedocs.adobe.com/labs/air/1/devappsflash/help.html?content=Filesystem_32.html
The above code should write a file, then read it back.
What's odd is I never get the "Hello" trace. Here's what's even more strange...
If I call the readLastLocation() function within iGotClicked (example:)
function iGotClicked (event:MouseEvent)
{
something = "Happy Day";
readLastLocation ();
}
I get the "World" trace.
So for some reason, writeFileStream.addEventListener(Event.COMPLETE, completedWriteLastLocation); is never getting fired, but readFileStream.addEventListener(Event.COMPLETE, completedReadLastLocation); is.
Any ideas on what I'm doing wrong?
NOTE:
There were a few times when I removed the COMPLETE eventListeners and forced the subfunctions, but I kept getting errors that the file was open and there was a sharing violation blah blah blah. Even though I .close()'d the filestream.