Flex mobile local storage.

Posted on 2014-08-23
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


    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();, 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();
, 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

    Perfect this answer helped me.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    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…
    DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now