That looks correct, and result  is the correct event and you should be able
to rely on "data" being complete.

 

trace(data); to check the content.

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of Cordova Aaron
Sent: Saturday, May 23, 2009 1:14 AM
To: [email protected]
Subject: [flexcoders] Working with files

 







I am trying to download a response from my server and then write that
response out to a local file. But the local file is never complete. The
amount of data I'm grabbing from the server can vary between a few K up to a
couple megs. I am using a HTTPService call to request my data and then
writing the file in my result function. I think that the data is not 100%
transfered when the HTTPService is emitting the result event. The local file
usualy varies from 26K lines of text to 56K lines and it is never 100%. In
my result handler the code looks similar to this:

private function resultFunction(e:ResultEvent):void
{
var data:String = e.result.toString();
var localFile:File =
File.applicationStorageDirectory.resolvePath("response.xml");
var fileStream:FileStream = new FileStream;

fileStream.addEventListener(Event.COMPLETE, localFileWritten);
fileStream.openAsync(localFile, FileMode.WRITE);
fileStream.writeUTFBytes(data);

fileStream.close();
}

Should I be listening for a different event to know when e.result is done
populating?



Reply via email to