Skip navigation
Claunchster
Currently Being Moderated

Entering/Saving Text Data with AS3

Jul 29, 2012 9:57 PM

Tags: #flash #data #text #as3 #cs5.5 #xml #actionscript3 #saving_data

I'm creating a desktop application for the beginning of the school year and I need to be able to have people manually fill in data in text fields (input text fields), primarily just names - and when they open the application they need that data to still be there.  I also want them to be able to edit and delete the data that they enter, possibly even using some kind of "save" button, just spitballin'.  What would be the best/easiest way to accomplish this?  Any ideas?

Thanks!

 
Replies
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 29, 2012 11:01 PM   in reply to Claunchster

    use the SharedObject.getLocal() static method.  you don't have to worry about reading and writing files.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 4:17 AM   in reply to Claunchster

    You can use SharedObject as kglad suggested, or you can also use AIR's File/FileStream to write to say a csv file, which can be useful if you want to graph data, etc. It's very easy actually - here's a nice 10 line example:

    http://www.numbmedia.com/blog/?p=159

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 30, 2012 10:26 AM   in reply to Claunchster

    you're making this a lot more complicated for no apparent reason.  

     

    if you need to create a human readable file, it makes sense to use the file class and in that case, and with the code you're now using you need to use readUTFBytes().  are you?

     

    and, if you don't need to use a human readable file, use the sharedobject:

     

     

    var mySaveNewDataArray:Array = new Array("txtName1","txtName2", "txtName3", "txtName4", "txtName5", "txtName6", "txtName7", "txtName8", "txtName9", "txtName10");

    var so:SharedObject=SharedObject.getLocal("dataSO");

    if(so.data){
    for(var s:String in so.data){  // this reads the data
    trace(s,so.data[s]);
    }
    }
    so.data.dataA=mySaveNewDataArray.concat();  // this writes the data
    so.flush()
     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 30, 2012 11:00 PM   in reply to Claunchster

    if your textfield is your_tf, use:

     

    var mySaveNewDataArray:Array = new Array("txtName1","txtName2", "txtName3", "txtName4", "txtName5", "txtName6", "txtName7", "txtName8", "txtName9", "txtName10");

    var so:SharedObject=SharedObject.getLocal("dataSO");

     

    var tfS:String = "";

    if(so.data){

    for(var s:String in so.data){  // this reads the data

    tfS+=so.data[s].toString();

    }

    }

    your_tf.text = tfS;

    so.data.dataA=mySaveNewDataArray.concat();  // this writes the data

    so.flush()

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 1, 2012 12:29 AM   in reply to Claunchster

    use:

     

    var tfA:Array = new Array(txtName1,txtName2, txtName3, txtName4, txtName5, txtName6, txtName7, txtName8, txtName9, txtName10);  // no quotes

    var so:SharedObject=SharedObject.getLocal("dataSO");

     

    if(so.data){

    for(var i:int=0;i<tfA.length;i++){

    tfA[i].text=so.data["tf"_text"+i];

    }

    }

     

    // when your textfields are ready to have their text saved, call saveTextF:

     

    function saveTextF():void{

    for(i=0;i<tfA.length;i++){

    so.data["tf_text_"+i]=tfA[i].text;

    }

    so.flush();

    }

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 1, 2012 7:56 PM   in reply to kglad

    use:

     

     

     

    var tfA:Array = new Array(txtName1,txtName2, txtName3, txtName4, txtName5, txtName6, txtName7, txtName8, txtName9, txtName10);  // no quotes

    var so:SharedObject=SharedObject.getLocal("dataSO");

     

    for (var i:int=0; i<tfA.length; i++) {

        if (so.data["tf_text_" + i]) {

            tfA[i].text = so.data["tf_text_" + i];

        }

    }

     

    // when your textfields are ready to have their text saved, call saveTextF:

     

    function saveTextF():void{

    for(i=0;i<tfA.length;i++){

    so.data["tf_text_"+i]=tfA[i].text;

    }

    so.flush();

    }

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 2, 2012 6:46 PM   in reply to Claunchster

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points