what is best way to write dispatch events in this Service class function?
I have the following function in a Service class
protected function writeToFile():void{
var destinationFile:File = File.applicationStorageDirectory.resolvePath(_newPath);
var fs:FileStream = new FileStream();
fs.open(destinationFile, FileMode.WRITE);
fs.writeBytes(_buffer, 0, _buffer.length);
fs.close();
}
this Service class should dispatch a SuccessfulCreateLocalFileEvent when writeToFile is successful and UnsuccessfulCreateLocalFileEvent if writeToFile is unsuccessful
I know that FileStream functions open and writeBytes may throw IOError if there is any problems. And all these FileStream functions all have void as return types.
I believe I need try catch, but I am not entirely sure how to do so.
Please advise.
This question is replicated at http://codereview.stackexchange.com/questions/12061/add-events-disp... Experimenting which site has better answers for such a question.
Comments are currently closed for this discussion. You can start a new one.
2 Posted by krasimir on 25 May, 2012 11:08 AM
Hello,
FileSteram class has its own events which are dispatched when the file operation is successful or not.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/...
Isn't it ok to use that.
3 Posted by kimcity on 26 May, 2012 02:05 AM
Hi krasimir,
you mean like this?
4 Posted by krasimir on 26 May, 2012 03:33 PM
Hi, yes. Exactly that thing.
5 Posted by kimcity on 26 May, 2012 06:41 PM
Hi krasimir,
thank you!
kimcity closed this discussion on 26 May, 2012 06:41 PM.