[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Flex mobile local storage.

Posted on 2014-08-23
Medium Priority
Last Modified: 2014-08-28
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?
Question by:aduvall
LVL 19

Accepted Solution

Gary Benade earned 2000 total points
ID: 40282523

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


Author Closing Comment

ID: 40290978
Perfect this answer helped me.

Featured Post

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question