Reputation: 49
To save and load character objects I am using File Stream in AIR, it is being targeted as an iPad app.
Event.complete is not firing and IOErrorEvent sometimes fires, I am at a loss.
Character class http://pastebin.com/pr6LSvMi
Thanks
-Anim8
Upvotes: 0
Views: 1181
Reputation: 8149
Few things:
URLLoader
, Loader
, FileStream
, etc. Basically, there is a small chance that the load will finish prior to the event listener being added, meaning the event listener won't even fire (extremely uncommon, but I have seen it happen with disk reads). Additionally, do not call FileStream.close()
until after the load has finished. The latter is, I believe, your problem. You are closing your connection before the connection has completed its load.So, remove fsR.close()
from
fsR.openAsync(fR, FileMode.READ);
fsR.addEventListener(Event.COMPLETE, LoadExistingCharacterObject);
fsR.addEventListener(IOErrorEvent.IO_ERROR, CreateNewCharacterObject);
fsR.close();
And add it to the handlers, LoadExistingCharacterObject
and CreateNewCharacterObject
. Additionally, you need to do the same in SaveCharacter
. Any time you use FileStream.openAsync()
, you cannot close
the stream until after the load has completed or errored out. If you use FileStream.open()
, you can close it immediately afterward since the application execution stops while the load is completed (FileStream.open()
is a synchronous operation and FileStream.openAsync()
is asynchronous)
You should read the LiveDocs for FileStream
.
Upvotes: 4