dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Saving variables to a txt file.

  1. #1
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46

    Saving variables to a txt file.

    Hi,

    I am using flash 5. I have created a kind of notepad that an admin can log into and write whatever in a textbox. now I would like to be able to save that text to a .txt file. I already have it set to load the .txt file when you go to the page, but I can't seem to be able to get flash to load the new text to the txt file.

    Oh, there are quite a few variables I would like to load to the text file. How would I go about doing this? I tried the FScommand "save" but as I understand it this is for local saves and not server use.

  2. #2
    Member
    Join Date
    Aug 2006
    Posts
    45
    heres alot of code that is really not slimmed down and it has a lot of useless crap, and its for flash 8, but what the heck


    trace($version);
    import mx.controls.*;

    // strict type instances on the Stage.
    var status_lbl:Label;
    var username_ti:TextInput;
    var password_ti:TextInput;
    var crap_ti:TextInput;
    var both

    /* Define a click handler for the submit_btn Button instance,
    which calls the checkForm function (defined below). */
    submit_btn.clickHandler = function() {
    getData();
    checkForm();
    getData2();
    };

    /* Create a listener object which is used with both the
    username_ti and password_ti TextInput instances.
    This listener "listens" for the "enter" event,
    which triggers when the enter key is pressed. */
    var formListener:Object = new Object();

    formListener.enter = function(evt) {

    getData();
    checkForm();
    getData2();

    };

    username_ti.addEventListener("enter", formListener);

    crap_ti.addEventListener("enter", formListener);



    // set the form focus to the username_ti TextInput instance.
    Selection.setFocus(username_ti);

    /* define the checkForm function, which is responsible for checking that the
    required fields are filled in and using LoadVars to send login information to the server to validate. */
    function checkForm() {
    // ensure that the username_ti field isn't blank.
    if (username_ti.text.length == 0) {
    // if the username_ti field is empty, display an error message in the status_lbl Label instance.
    status_lbl.text = "Please enter name.";
    // set the form focus to the username_ti TextInput instance.
    Selection.setFocus(username_ti);
    // exit the checkForm function.
    return false;
    }/* if the password_ti TextInput instance is blank,
    display an error message in the status_lbl Label instance and exit the checkForm function. */
    if (this.crap_ti.text.length == 0) {
    status_lbl.text = "Please enter data.";
    Selection.setFocus(this.crap_ti);
    return false;
    }

    // clear the status_lbl Label instance
    status_lbl.text = "";
    /* define two instances of the LoadVars object.
    One is used to hold the variables being sent to the server-side script, */

    }
    function getData() {
    var result_lv:LoadVars = new LoadVars();
    result_lv.onLoad = function(success:Boolean) {
    // If Flash is able to successfully send and load the variables from the server-side script...
    if (success) {
    // if the server returned the value of isValidLogin with a value of 1...
    status_lbl.text += "<b>Title sent!</b><br>";
    /* this code is only executed if for some reason the SWF is
    unable to connect to the remote page defined in LoadVars.sendAndLoad */
    } else {
    status_lbl.text = "<b>Unable to connect to login URL</b>";
    username_ti.enabled = false;
    password_ti.enabled = false;
    submit_btn.enabled = false;
    }
    };
    var send_lv:LoadVars = new LoadVars();
    send_lv.tit = username_ti.text;
    trace(username_ti.text);
    send_lv.sendAndLoad("http://zachpad.tripod.com/cgi-bin/modtest.cgi", result_lv, "POST");
    }

    function getData2() {
    var result2_lv:LoadVars = new LoadVars();
    var send2_lv:LoadVars = new LoadVars();

    ////////////////////////////////////////// Sucess function

    result2_lv.onLoad = function(success:Boolean) {
    // If Flash is able to successfully send and load the variables from the server-side script...
    if (success) {
    // if the server returned the value of isValidLogin with a value of 1...
    status_lbl.text += "<b>Message Sent!</b><br>";
    /* this code is only executed if for some reason the SWF is
    unable to connect to the remote page defined in LoadVars.sendAndLoad */
    } else {
    status_lbl.text = "<b>Unable to connect to login URL</b>";
    username_ti.enabled = false;
    password_ti.enabled = false;
    submit_btn.enabled = false;
    }
    };

    /////////////////////////////////////////////ENd


    send2_lv.full = crap_ti.text;

    trace(crap_ti.text);

    send2_lv.sendAndLoad("http://zachpad.tripod.com/cgi-bin/modtest.cgi", result2_lv, "POST");
    }

    //mailData.onLoad = function(){
    /*We are expecting 2 variable value pairs
    from the server

    1. status : A string with a message like Message Sent\nThank You
    2. sent : A number which is either 0 or 1. 0 meaning not sent and
    1 meaning sent sucessfully*/

    //Since all external data comes in as a string.. we convert
    //the sent variable from a string to a number.
    //this.sent = Number(this.sent);

    //if (this.sent == 1) {
    //trace("Message Sent successfully");
    //} else {
    //trace("Message could not be sent");
    //}//End if

    //also trace the other variable with a PHP message
    //trace(this.status);
    //};


    it also has 3 text things, stated at the begining, which you will have to make. If you don't have flash 8, i suggest you pirate it. (Just kidding(or am i?(I'm only half kidding(actually, only 1/4 kidding))))

  3. #3
    Member
    Join Date
    Aug 2006
    Posts
    45
    oh yeah, the modtest cgi--remove that and change it to your own dierctory.

    here's: another bulky-cgi file that i used:

    #!/usr/local/bin/perl

    require "subparseform.lib";

    &Parse_Form;
    # //////////////////////////////////////

    print "Content-type: text/html\n\n";

    # //////////////////////////////////////

    # -----Getting the Referer
    $refer=$ENV{HTTP_REFERER};
    # -----END


    # ----An old loop that got all the ENV variables
    # foreach $env_var (keys %ENV) {
    # print "<BR><FONT COLOR=red>$env_var</FONT> is set to <FONT COLOR=blue> $ENV{$env_var} </FONT>";
    # }


    }
    $ltfull=length($formdata{full});
    $lttit=length($formdata{full});
    if (($ltfull>3) && ($lttit>0))
    {
    print "What da? @text";
    open(DATA,">>flash2.txt") || die("Cannot Open File");
    print DATA "@text";
    close(DATA);
    }
    else
    {
    print "File corrosion u mutha-";
    open(DATA,">>flash2.txt") || die("Cannot Open File");
    $userip=$ENV{REMOTE_ADDR};
    $userbr=$ENV{HTTP_USER_AGENT};
    print DATA "File messed-up. Remote addr is $userip\nBrowser is $userbr\n";
    close(DATA);




    print <<END;
    <center><hr size=1 width=50%>$ENV('HTTP_USER_AGENT')</center>
    </body>
    </html>
    END



    put that in a text file and save it as whatever .cgi

  4. #4
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46
    thx! I'll give that a shot.

    Is there any way to do it with php? I know.. I'm askin alot.. but I'm just more comfoftable with php.

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Seoul, South Korea
    Posts
    1,310
    Take a look at the following
    Attached Files Attached Files
    !.....................................COMING SOON

  6. #6
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46
    Thx, but that seems to be for specific variables. My flash movie actually creates it's own variables so I never know what the names will be. Is there and way just to send all variables in a movie to a txt file?

  7. #7
    Member
    Join Date
    Oct 2004
    Posts
    67
    I'm very interested in the same thing. I have been using fscommand to launch an external application written in VB to collect data that is entered into a contest form, but I really need to find a way to keep it in flash. It appears that fscommand only works if the flash presentation is published as an EXE. Unfortunately, that doesn't work for me. I just spent a moth in VB to develop the contest form and now I find that Flash can't launch it from a swf file.

    So, how can you pass variables out to a text file easily in Flash?

  8. #8
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Removing any helpful previous posts I mistakenly contributed to these forums.

    See ya FK'ers
    Last edited by NTD; 10-19-2006 at 06:18 AM.

  9. #9
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46
    Some great tuts there. I learned a thing or two just by browsing them.

    However... again it seems that you are required to know the strings for all of the variables in the movie. So, must I assume that there is no way to just save all the variables to a file without having to list every single one in the actionscript.

    No Save All command? The only way, again, I can think of to do this is with the Fscommand "save". Which doesn't work online.

    Wait.. I remember making an email form once that just "POSTed" the variables straight to an email addy. I didn't have to specify every one, could this method be used to write to a .txt file?

  10. #10
    Member
    Join Date
    Oct 2004
    Posts
    67
    In my case, the computer running Flash is a standalone machine without any external connections. I'm actually working with kiosks, so everything needs to remain self contained. I think I will start another thread with my $6,000,000 question about opening an exe from a swf. I know it's not "technically" possible. But, I think there might be a hack. That way, in my case, I can use a VB application for data entry.

  11. #11
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    I too have a link in my footer (save-2-text)

    that outlines how to use PHP (Im sure very similar to what NTD has as well)...

    but yes, you DO need to know what VARS to send to PHP.. you can use a loadVar object..and send the whole object.. but you would still need to add all textFields and other variables to the object.

  12. #12
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    I am using a REALLY stupid server that I have no control over. (beurocracy)

    This server does not run PHP, or Perl, or anything to my knowledge. It is really just a LAN folder that can be accessed through our intranet and is given a web address. I am not a network guy so I really don't know how it is setup.

    My problem is that I am trying to create a simple form that does not use any other server run code. I have access to a lot of public lan folders that the users will also have access to if they can get to our intranet. Is there a way that flash can create or append to a text file on a LAN?

    I just want to save some text without using php or perl or any of those server scripting languages. Is this possible? The flash security is killin' me, lol.

    To let you know how desperate I am, my current form is a word document that has an imbedded VBAmacro in the submit button to save the file to a LAN and then close itself when done. Talk about clunky, but I can't find a better way to do it with this braindead server I am dealing with.

  13. #13
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46
    That really sux.. I was sure there was a way to do it.

    The problem with including all the variables to the script, is that, Flash itself is creating the variable name while the movie is running. I know what every possible variable name is, but writing code for hundreds or even thousands of variables is insane. It would take me years to write out all the variables.

    My movie is a calender that you can click on the day, and enter some text for that day. It is a perpetual calender, so that would mean I would have to make 1 variable for each day. Span that over the possibility of many years of use and the amount of variables is astronomical.

  14. #14
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Quote Originally Posted by Alluvian
    I am using a REALLY stupid server that I have no control over. (beurocracy)

    This server does not run PHP, or Perl, or anything to my knowledge. It is really just a LAN folder that can be accessed through our intranet and is given a web address. I am not a network guy so I really don't know how it is setup.

    My problem is that I am trying to create a simple form that does not use any other server run code. I have access to a lot of public lan folders that the users will also have access to if they can get to our intranet. Is there a way that flash can create or append to a text file on a LAN?

    I just want to save some text without using php or perl or any of those server scripting languages. Is this possible? The flash security is killin' me, lol.

    To let you know how desperate I am, my current form is a word document that has an imbedded VBAmacro in the submit button to save the file to a LAN and then close itself when done. Talk about clunky, but I can't find a better way to do it with this braindead server I am dealing with.
    no..there is NO WAY!. As stated...FLASH can NOT latently write to text files (or dump to a DB)..it will need a 3rd party solution for that.

    If this was NOT web/browser based.. there MAY be some solutions (but I havent looked into it much)

  15. #15
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Quote Originally Posted by kland
    That really sux.. I was sure there was a way to do it.

    The problem with including all the variables to the script, is that, Flash itself is creating the variable name while the movie is running. I know what every possible variable name is, but writing code for hundreds or even thousands of variables is insane. It would take me years to write out all the variables.

    My movie is a calender that you can click on the day, and enter some text for that day. It is a perpetual calender, so that would mean I would have to make 1 variable for each day. Span that over the possibility of many years of use and the amount of variables is astronomical.
    I guess I just dont understand then...doesnt seem to hard to me.

    I mean.. what ALL can the user do? Just click/open the day on the calander and enter in some notes? Thats what? all of 1 textField??

    So thats ALL you need to dump to the textfiled. is that ONE variable.
    You can export a textFile using the DATE object or something.. that way any day you click on in he calandar (Tuesday, September the 12th square) the code on the 'click' loads the 09122006.txt file or something..

    Im sure there are many ways.

    If you thinking of saving EVERYTHING to one text file.. I recommend against it. Over time it will lag and jack up loading time. Besides..why load data the user may never see?

  16. #16
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46
    You kinda have the Idea.

    The calender is generated using your computers clock. In the basic movie, there are only about 10 variables, However, each time the person clicks on a day and enters text, then clicks "ok" a variable is created. (I.E. &september122006="whatever"). This way there are only variables created for days that have a note. You can't see the notes on the calender but the date gets highlighted. Click on a highlighted date and the text pops up.

    If each day had it's own .txt file, that too would be insanely huge. Imagine hundreds of textfiles being loaded to the movie..

    Honestly, to me, this is a big flaw in the design of flash. Flash is great for beign able to import variables from files but having it post them, or save them is like pulling teeth. IMO, you shouldn't have to slap all kinds of extra php of cgi coding to get a simple txt file.

  17. #17
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    If thats how you feel. I dont mind it too much. It does protect alot of things.

    If you dont want to use text files..then use a DB...either way you'll need somethign to take the data form FLASH and dump it to your choice.

    you can ONE textFile called 'data' (for example) and inside..just save one variable to the file for, each day that has infor for it.

    data.txt >> (inside)

    september122006=whatever the user input&september132006=some more junk..etc..

    However I think it is silly to load data you wont see or potentially not see.

    If you dont want a database.. Im not sure what to tell ya if you dont want to use flat text files. IMHO 1 tetx file is bad...and while multiple text files is somethign you said you DIDNT want.. the load times would be small..as you would ONLY load them once you clicked on the highlighted date.

    How do you have your "highlight" logic worked out?

  18. #18
    Member
    Join Date
    Sep 2006
    Location
    Montreal
    Posts
    46
    It may be easier if you just see the file.

    My movie is based off of this:

    The highlight is:
    this._name = this.myname;
    if (eval("_root." add _name) ne "") {
    select._visible = true;
    } else {
    select._visible = false;
    }
    stop ();

    I honestly don't care what option I use DB or otherwise. But the problem still stands that I would have to create an external file with all possible variables in it.

  19. #19
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    The highlight code doesnt make sense to me...(cant you just explain it?) It must have a 'list' to go off of...correct? Something that says yes or no to turn on the 'highlight'.

    ne is that the same as != (not equals?).. so what is ADD_NAME?

    anyways.... I guess I still dont understand..

    what external.txt file would you have to create? and what are "all these variables" you need create that you keep saying?

    To me, as youve explained it, there is only 1 variable for each day...no? there is only 1 thing the user can do..correct?..and thats INPUT NOTES? he hits saves button...thats it right?..cause you havent said anythign else?

    simple walk through:

    user clicks box.. form appears.... he enters in notes..hits save..closes box.

    when user its save...this calls a php script...that grabs the text in the input field...creates a textFile named (whatever the day/date/box he clicked) 09122006.txt...dumps the data to it...

    BAM!

    thats it.. it saves it to some folder called (calandarData..or whatever)..

    now if your day/date is highlighted..you click to open the box..it looks for a textFile called (whatever day/date you clicked on)..and displays the text.

  20. #20
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Removing any helpful previous posts I mistakenly contributed to these forums.

    See ya FK'ers
    Last edited by NTD; 10-19-2006 at 06:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center