# Add var into .txt

**URL:** <https://forum.kirupa.com/t/add-var-into-txt/14007>\
**Category:** Uncategorized\
**Created:** [February 20, 2003, 9:14pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007 "2003-02-20T21:14:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![funkyjones](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@funkyjones](https://forum.kirupa.com/u/funkyjones)\
**Post date:** [February 20, 2003, 9:14pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/1 "2003-02-20T21:14:09Z")

</div>

how can i add a content of a variable into a .txt file?  
simple question needs a simple answer.  
Cheers!  
/ZeusVL

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 3:05pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/2 "2003-02-21T15:05:21Z")

</div>

load the variables using the loadVariablesNum() method. If you specify 0 then the variables will load to \_level0 which equates to \_root if your movie only contains one level

Declare you variables as you would in Flash and separate variables with ampersands (don’t add any additional spaces) e.g.

dog=25&oatmeal=“farinacious”

Don’t forget that if you’ve a slow server then there can be a delay between client request and server response and if your server hangs in the middle of serving a long txt file then your vars may be incomplete

It’s good practice to include a “junk” variable at the end of your txt file so that you know all the vars have been loaded and declared

e.g.

dog=25&oatmeal=“farinacious”&alldone=true

then if you call the txt file using

alldone=false  
loadVariablesNum (“vars.txt”, 0);

you can perodically test for alldone and handle any errors that arise

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 3:30pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/3 "2003-02-21T15:30:49Z")

</div>

hmm, Im sorry but i didnt quite understand.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 3:59pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/4 "2003-02-21T15:59:34Z")

</div>

Create text file called vars.txt containing the text

dog=25&oatmeal=“farinacious”

with no additional spaces, carriage returns or line breaks. (Assuming that you want to declare two variable one a numerical variable called dog with a value of 25 and the other a string variable called oatmeal with a value “farinacious” - obviously you’ll need to edit this to suit your purposes)

Then it the place where you want to declare your variables i.e. the place where you would otherwise type

var \_root.dog=25  
var \_root.oatmeal=“farinaceous”

instead type

loadVariablesNum(“vars.txt”,0)

and make sure that vars.txt and your swf are in the same folder

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 4:43pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/5 "2003-02-21T16:43:36Z")

</div>

hmm, could you show me an example?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 5:00pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/6 "2003-02-21T17:00:07Z")

</div>

here we go:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 5:36pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/7 "2003-02-21T17:36:18Z")

</div>

Try looking at the enclosed zip loadVarsExample.zip

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 5:37pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/8 "2003-02-21T17:37:28Z")

</div>

Have a look at

[http://www.kirupaforum.com/showthread.php?s=&postid=118268](http://www.kirupaforum.com/showthread.php?s=&postid=118268)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 5:59pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/9 "2003-02-21T17:59:25Z")

</div>

thats not the first time that happens

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 6:46pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/10 "2003-02-21T18:46:07Z")

</div>

I think he’s asking how to save text file from Flash… FSCommand save still work in Flash 5???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 6:50pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/11 "2003-02-21T18:50:08Z")

</div>

yeah after i saw your example I think u have understood me.  
fscommand (“save”, “bla.txt”)  
u mean?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 7:15pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/12 "2003-02-21T19:15:31Z")

</div>

Yes… That’s what I have meant, but I am not sure if that still works or not… I know that it should work if your user have FP5 installed, but it’s kinda outdated now, so I am afraid that wouldn’t do any good for you…

Are you trying to save a text file for the projector or the web based one??? And you DO use F5 for this project, right???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 7:18pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/13 "2003-02-21T19:18:04Z")

</div>

Ok.  
Yes I use F5 for this. Well it´s just a experiment, but I think i will use it on a webbased one.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2003, 7:58pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/14 "2003-02-21T19:58:24Z")

</div>

Well… I guess it’s your job to search the web to see if fscommand save still works or not…

If you have a project for the web which needs to save a text file, then you gotta get the server side script to do the job… No other way I know of rather than that…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2003, 2:22pm UTC](https://forum.kirupa.com/t/add-var-into-txt/14007/15 "2003-02-22T14:22:06Z")

</div>

If you want to save to a txt file in Flash 5 then you’ll need a server side script (VB, php, etc) and sufficient server permissions to set the chkmod of your txt file (777 = read/write/execute).

You pass your variables to the server script using the getUrl() method specifiying GET/POST as appropriate.

Alternatively, if you only want to use Flash, then MX has the ability to store persistent local data.
