Skip to main content
Inspiring
June 6, 2012
Question

Newbie question: Saving User Data on iPad

  • June 6, 2012
  • 3 replies
  • 968 views

Hi

I am working on an App for iPad in Flash CS5.5.

In the app the user will be writing poetry and saving text on the iPad locally.

I need them to be able to decide which poem they load back into the app.

It seems to me this will qualify ofr saving to the /Documents folder.

I have looked at shared objetcs and dont think it will do that job.

Can I use FileReference on an iPad?

Will the user be able to browse the different files he/she has saved?

Can someone point me to some example code for saving to and loading from /Documents?

Best

Tommy Banana

This topic has been closed for replies.

3 replies

Kartik_Mehta
Inspiring
June 6, 2012

Hello,

To save the file at a location on the device try using File.applicationStorageDirectory

Regards,

Kartik.

The_Preacher1
Inspiring
June 7, 2012

Here is some basic code that will work.

import flash.filesystem.*;

import flash.events.Event;

var f:File;

var fs:FileStream;

var myDATAstring:String;

function CheckSettings():void{

            f = File.applicationStorageDirectory.resolvePath("Storage_File_Name.txt");

            if(f.exists){

                getDATA();

            }else {   

             trace("Nothing stored yet");

            }

}

function getDATA():void{           

          fs=new FileStream();

          fs.addEventListener(Event.COMPLETE, onFileOpened);

          fs.openAsync(f, FileMode.READ);

}

       

function onFileOpened(e:Event):void{

            myDATAstring=fs.readUTFBytes(fs.bytesAvailable) as String;

           fs.close();  

}

//****** Use this to save the high score *******       

function SaveDATA(s:String):void{       

            f = File.applicationStorageDirectory.resolvePath("Storage_File_Name.txt");

           fs=new FileStream();

          fs.openAsync(f, FileMode.WRITE);

          fs.writeUTFBytes(s);

         fs.close();

}

Inspiring
June 7, 2012

Great Thanks!!

Tom Bancroft

07974983701

Sent from my iPhone