Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving variables to a local folder

Status
Not open for further replies.

isNaN

Programmer
Aug 2, 2002
24
0
0
US
Hello,

I'm creating a game in flash and I want to create some user defined preferences that can be saved and reloaded at a later time. I just want to save a bunch of variables to a file in the directory that the .swf is in (or ideally in a directory below that directory). Saving it as plain text would be fine. I looked into doing XML, but it just seems overkill for what I want to do.

I have this on the main timeline:

testSave = new LoadVars();
testSave.message="Hi there!";

then a movieClip button that does this:

on (press) {
_root.testSave.send("testSave.txt");
trace (_root.testSave.message);
trace ("I did something");
}

I get the traces but no file. What am I doing wrong. It seems that this should be really simple.

isNaN(jaxon)
 
I think you'd be better off with this:

Code:
on (press) {
    fscommand ("save", "filename.txt");
}

Every variable will be saved to the file like so:

Code:
&testSave=hello&variable2=whatever&somethingElse=hi there

To load the variables:

Code:
on (press) {
    loadVariablesNum ("filename.txt", 0);
}
 
I have done a bunch of research on this and had a brief discussion about it on another flash related forum.

I have some more relevant details:

This is intended to be a flash projector or stand alone flash file when I'm done. Someone recommended the SharedObject technique but I don't think that will work in this case. Partly because SharedObjects uses the relevant domain to store the data (as far as I know) and more because I will probably have to much data to save using SharedObjects.

I also found some applications that will "wrap" a flash projector and extend its functionality. Those would probably allow me to do this, but they only work on Windows (and cross-platform is important to me).

Supra: Thanks for the response, I appreciate it. That would be awsome if it works, but I think I missed something or I need more details. How does the fscommand know what variables to send? Also, what is your fscommand communicating with? I apologize for being vague before. I had only just begun to explore this problem and didn;r realize what all the issues would be.

I've pretty much decided that I am going to have to write something in C++ or Java to catch the data and save it to disk. I'm probably going to use C++.



 
There is no need to write any other program to save variables to a text file. FSCommand("save","file.txt"); is an undocumented Flash command which saves all text fields that have been assigned a variable. For instance, let's say you have a text field set to Dynamic and the variable is "score". Let's say the user's current score is 360, so that's what the text box says. Upon executing the save command, &score=360 will be written into the text file. All other text fields that are assigned variables will also be written into the text file. When you load the text file, those text fields will be filled in by the variables saved in the text file. Create a simple Flash project with 2 buttons and 1 dynamic text field. Assign the text field the variable "test". Write something in the text box like "hello". Publish the movie. Now open the movie and click the button which is set to save your variables. Look in the folder the movie is in and you will see a new file "file.txt" or whatever you named it. Open it up and your variable "test" is there. Now change the value of &test=hello to &test=hi. Go back to your movie and click the button which has been assigned to load variables. Your text box will change from "hello" to "hi". I just tested this not even 2 minutes ago and it works flawlessly. I would just hate to see you spend time creating an add-on program for absolutely no reason. So in short, the FSCommand sends ALL variables which have been assigned to text fields. The FSCommand is not communicating with anything. It's a built-in Flash command which writes a text file of variables. It's the simplest and best way to save information.
 
Hmmm, no luck, maybe that only works on Windows. I just tried it with no results on Mac OS X.

I could be doing something wrong, but I followed your instructions very closely. I also tried having the button call a function on the main timeline and having the function execute the fscommand.

.....

Yep, it looks like Mac wont do it. I just found this...


Also, are you using Flash 5? Because it looks like MX wont do it either. I found some other sites that support these claims as well.

that sucks. :-|

However, thanks a lot for the help. It was looking real promising for a second there.
 
This feature works only from the standalone Flash player. If you want to implement this as an online feature, you will need to look at using PHP with XML or MySQL or something.
 
Ah I apologize, I wasn't aware you were using Mac. Well, is there a command prompt similar to DOS on Mac? If so, you can also use that to write to a file, and also with much more control. frozenpeas, yes you cannot save a file if you're working online, but you do not need the standalone player on your local drive. The SWF will save with no problems, assuming you are using Flash 5 on a windows box. Get back to me about the command prompt isNaN.
 
Yeah, Mac OS X has a command prompt called the terminal which basically accepts all things UNIX.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top