Flex mobile local storage.

I have a simple mobile app for ios.  The app contains 2 text fields and a submit button. I have written so that data input into the fields is saved to MySQL db.  It works fine as long is there is network coverage but of course when there is none you can't save the data.  My question is how can I save this data locally then upload when network coverage is available?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary BenadeCommented:

Your would store yout data in localStorage, if you have complex data to save it makes sense to use a structured format, I chose XML in the following example

// you need these imports
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

// add the fields you want to store to this structure
var settings:XML =

// save settings - save your data here when you are offline
settings.myData = "Update me with the new data";
settings.moreData = 999;

var prefsFile:File = File.applicationStorageDirectory;
prefsFile = prefsFile.resolvePath("settings.xml");

var stream:FileStream = new FileStream();
stream.open(prefsFile, FileMode.WRITE);
stream.writeUTFBytes( settings.toString());

/// read data back - do this when you are back online
var prefsFile:File = File.applicationStorageDirectory;
prefsFile = prefsFile.resolvePath("settings.xml");
if( prefsFile.exists)
      var stream:FileStream = new FileStream();
      stream.open(prefsFile, FileMode.READ);
      settings = XML(stream.readUTFBytes( prefsFile.size));
//use the data from the XML object here. eg:
// sendDataToServer( settings.myData);
// sendDataToServer( settings.toString()); // to send the whole XML object


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aduvallAuthor Commented:
Perfect this answer helped me.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.