Flex mobile local storage.

aduvall used Ask the Experts™
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?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

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



Perfect this answer helped me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial