A Flash Developer Resource Site

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

Thread: WRITING external text files

  1. #1
    Junior Member
    Join Date
    Oct 2001
    Posts
    17
    There is loads of useful stuff about how to load vars into a Flash movie from an external text file, but I can't seem to find out how to WRITE me a text file in the FIRST place.

    grrr..

    any help appreciated.

  2. #2
    Junior Member
    Join Date
    Jun 2000
    Posts
    11
    you can use php:

    make a file called write.php that consists of:

    <?php $a = fopen("yourfile.txt", "a");
    fputs($a, "$yourvariable\n");
    fclose($a);
    ?>

    then on your button put:

    yourvariable = "whatever"
    loadVariablesNum ("write.php", 0, "POST");

    should work hope it helps



  3. #3
    Junior Member
    Join Date
    Oct 2001
    Posts
    17
    Thanks, that's cool. But I also need to know how to write txt files from within Projector.

    Is it something to do with FsCommand "save"...?

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    170
    fscommand ("save", "yourfile.txt")

    it will save all varibles to .txt file in standard "amperstand format"

    Alex

  5. #5
    disMemberEd Skorp|oN's Avatar
    Join Date
    Mar 2001
    Location
    Romania
    Posts
    167

    hey, could you be a little more specific ?

    yo, metaminds, did you say that fscommand ("save"..) saves ALL of the variables in your movie ? Then how could you read them back ??? I'm kinda' confused here...

  6. #6
    Junior Member
    Join Date
    Oct 2001
    Posts
    17
    mm. yep. I have to agree with Skorpy.
    I tried the fscommand "save", but I need to be a little more specific with the vars I choose to save to each txt file I want to create.

    Ideally, I want to be able to specify "these vars" to be saved in "this".txt file. ie a txt file with an expression for a name.

    // deuce... metaminds to serve. //


    Originally posted by metaminds
    fscommand ("save", "yourfile.txt")

    it will save all varibles to .txt file in standard "amperstand format"

    Alex

  7. #7
    Senior Member
    Join Date
    Mar 2001
    Posts
    246
    There's another way (PC-only, I believe); have a look here:
    http://www.were-here.com/forums/show...threadid=43302

    hc

  8. #8
    Senior Member
    Join Date
    May 2001
    Posts
    170
    hi all,

    fscommand "save" will save variables they are available just now. Simple technique to select variables to save is following:

    1) create MC, for example name it varContainer
    2) make copy of needed variables to this MC, for example:
    _root.numberOfItems = _root.varContainer.numberOfItems
    etc.
    3) place button inside of varContainer MC with following script:
    on (release) {
    fscommand("save", "variables.txt")
    }

    to read these saved variables from saved text file, do following:

    1) create empty MC, call it for example "loader"
    2) place this script on MC as a handler:
    onClipEvent (load) {
    //loads variables from external file
    this.loadVariables("variables.txt")
    }
    //checks if data are loaded correctly
    onClipEvent (data) {
    //sends variables, loaded from external file, to _root
    this.numberOfItems = _root.numberOfItems
    }

    hope this helps

    Alex

  9. #9
    Senior Member
    Join Date
    May 2001
    Posts
    170
    oh, I forgot, GMode... you can use expressions to construct name of txt file:

    newNameForTextFile = "items" + ".txt"
    fscommand ("save", newNameForTextFile)

    naturally you can use a chain of variables to construct this name.

    If you need to save more txt files with various variables, create more MCs in directions I placed in last post..

    Alex

  10. #10
    Member
    Join Date
    Aug 2000
    Posts
    57
    this is all very useful information, but I am wondering this..

    I would like to be able to actually copy content (variable?) from a single text field and write that content into the text file being saved..

    how would you write that in this line of code:

    newNameForTextFile = "items" + ".txt"
    fscommand ("save", newNameForTextFile)


    if the name of the field I am copying content from is named "input"..

    The text will also need to be able to be loaded back into the swf later on..

    thanks


  11. #11
    Senior Member
    Join Date
    May 2001
    Posts
    170
    hey, Sintwar

    if you are using fscommand save, name of txt file and variable names are very different problems. You can give to txt file name what you want, but when you save variables to this file, INSIDE of this text file will be saved variables in following form:

    &input="content of your input text field"
    &anotherVariable="another content..."

    and as I said in previous post, you can load this txt file, it will load these variables from txt file as a independent string variables with names "input", "anotherVariable" etc., you can manupulate them, you can load them to text fileds, parse etc....

    but, be affraid, fscomman save works ONLY in standalone projector mode, you can not test it Flash using ctrl+enter or using html with attached .swf

    Alex

  12. #12
    Junior Member
    Join Date
    Oct 2001
    Posts
    17

    Smile



    thank you all.

    metaminds - I owe you a beer (or six.. )

  13. #13
    Senior Member
    Join Date
    May 2001
    Posts
    170
    glad to help!
    hope you will help me with those six bears

  14. #14
    Member
    Join Date
    Aug 2000
    Posts
    57
    Where would I put the
    &input="content of your input text field"

    in correspondence to this?

    newNameForTextFile = "items" + ".txt"
    fscommand ("save", newNameForTextFile)


    I basically just don't know where to put it to make it actually function..

    I tried this:

    newNameForTextFile = "items" + ".txt"
    fscommand ("save", &input="content of your input text field", newNameForTextFile)

    but that just gives me errors

    I don't know what to do!!

    pls help!

  15. #15
    Senior Member
    Join Date
    May 2001
    Posts
    170
    Sintwar,

    Flash saves variable from itself...
    please, read my previous posts carefully

    an example for you:

    1) let say, you have on _root dynamic text field with name "myTextField". It is string variable.

    2) you need to save this string variable "myTextField" to external file. To prevent save all variables from _root and save only this one variable, make a new MC, call it "saver".

    3) make a copy of "myTextField" variable to this MC:
    _root.myTextField = _root.saver.myTextField

    4) place button inside "saver" MC with following script:
    on (release) {
    fscommand("save", "variables.txt")
    }
    if you need to generate name of text file dynamically, you can use for example

    newNameForTextFile = "variables" + number + ".txt"
    fscommand ("save", newNameForTextFile)

    or use another scripting technique, which can produce various names....

    naturally you can use 3rd a 4th script on this one button:
    on (release) {
    _root.myTextField = _root.saver.myTextField
    fscommand("save", "variables.txt")
    }


    this script will produce "variables.txt" file, and inside of this text file will be "myTextField" variable automatically saved.

    if you will have more variables inside "saver" MC, they all will be saved together in one text file

    Alex

  16. #16
    Member
    Join Date
    Aug 2000
    Posts
    57
    ugh this message board is a piece of "blank blank blank"

    ok let me try this again..


    ok I have 3 elements on the stage (_root)..

    1: a dynamic text field named "uname" with content "Richard"
    2: a dynamic text field named "text" with content "This is only a test"
    3: a mc named "saver" (insance and movie)

    in saver (_root.saver)I have 2 elements..

    1: button with following script:

    on (release) {

    unamevar = _root.uname;
    _root.saver.saveline = _root.text;

    NameFile = "unamevar" + number + ".txt"
    fscommand ("save", NameFile)

    }

    2: an empty dynamic text field named "saveline"


    The end result is as follows:
    The file saved is named "unamevar.txt"
    The text content is this "&text=This is only a test&uname=Richard"


    The desired end result should be:
    text file named "Richard.txt"
    text file content "&saveline=This is only a test"


    what am I doing wrong?

    thanks for any help..

  17. #17
    Senior Member
    Join Date
    May 2001
    Posts
    170
    ou ou ou, sorry, Sintwar, my error!!! flash will save variables only from _root!!!


    I see one problem in your script:

    NameFile = "unamevar" + number + ".txt"

    if you put "unamevar" in parentheses, flash read it as a string, not variable, so correct syntax is:

    NameFile = unamevar + ".txt"

    (you do not need to use variable "number", it was only example in my previous post)


    so, do following:

    1) make an MC from those two dynamic text fields ("uname" and "text"), name it "textFields"
    2) on button place these scripts:

    on (release) {
    this.unamevar = _root.textFields.uname
    _root.saveline = _root.textFields.text

    NameFile = this.unamevar + ".txt"
    fscommand ("save", NameFile)
    }


    sorry for my previous mistake, just now I tested scripts and all works fine.

    One notice: there is no problem when you have more variables in your text file, when you will load them, you can use only one you need...


    Alex

  18. #18
    Member
    Join Date
    Aug 2000
    Posts
    57
    ahhh thank you, thank you......

    Well, here is what I am doing..

    I am developing a game that will basically have a save game feature.. however, what it is doing essentially is grabbing all the information from every field that I tell it to grab info from, creating one string out of them all and then double encrypting that string..

    the outcome is actually quite huge, so I figured it would be best to dump all the encrypted code into a txt file instead of making them copy it and paste it back into a field, they will just have the option to type in their user name and it will automatically load the game for them..

    once they go to load a game and type in their username, it will load that users game directly from that particular txt file and un-encrypt the code on the fly..

    unfortunately as you said, the game will have to be a standalone projector in order for me to do that..

  19. #19
    Member
    Join Date
    Mar 2001
    Location
    Lisbon, Portugal
    Posts
    64
    hi,
    i've read all the posts but still i didnt figure out one issue.
    Is it possible to flash write a text file online with php?

    I have movie to post some variables.
    Another that should read those variables from an external file.

    I done that with the projector as u guys explained, but for me wont work cause i need that online.

    please please help me

    thanx

  20. #20
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi trolljanz,

    quite sure - use
    loadVariablesNum('save.php'. 0, 'POST')
    and all the flash vars on the main timeline are available for php to save

    Musicman

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