Posted by ramza in SWF Studio V3 on Aug 24 2011, 07:05 am

i want to save a variable to txt file and then loaded back when a button is pushed.
i tried this:

ssCore.FileSys.writeToFile({path:"desktop://file.txt", data:"money1"+"="+money});





but it returns undendified
can someone help me please!!!

Posted by northcode in SWF Studio V3 on Aug 24 2011, 10:14 am

There are a couple of problems with what you've done.

You have not enabled synchronous commands, which you will need to do if you want to get results from an ssCore call directly, otherwise you need to use a callback. Read about synchronous commands vs asynchronous commands (the default).

The FileSys readFile and functions don't work like the old Flash 5 SAVE fscommand or like loadVariables. You need to read the documentation for those commands too.

If you set the data for writeToFile to "money1=5" then that's EXACTLY what you'll get back from readFile so you'll have to parse the data to get the value you want back out of the string. It would actually be easier to store the data in XML format or in an INI file (using the INIFile plugin)

ssDefaults.synchronousCommands = true;

function saveMoney(data:String):void
   var r:Object = ssCore.FileSys.writeToFile({path:"desktop://file.txt", data:data});
   if (!r.success) 
      ssDebug.trace("error saving data:"+r.Error.description);

function loadMoney():Number
   var money:Number = -1;

   var r:Object = ssCore.FileSys.readFile({path:"desktop://file.txt"});

   if (r.success)
      money = Number(r.result);
      ssDebug.trace("error loading data:"+r.Error.description);

   return money;

Posted by ramza in SWF Studio V3 on Aug 25 2011, 03:43 am

i simplify the above code to this:

ssDefaults.synchronousCommands = true;

var a:Object = ssCore.FileSys.writeToFile({path:"desktop://file.txt", data:money});

var a:Object = ssCore.FileSys.readFile({path:"desktop://file.txt"});

money = Number(a.result);

it works but when i put another variable, values on the game shows "NAN" and i have many variables to add.
how can i fix that or how it works with ini file?

Posted by northcode in SWF Studio V3 on Aug 25 2011, 12:51 pm

The data that the FileSys plugin lets you save is unstructured, it's just a string. YOU have to decide how to store the variables in a single string and then YOU have to parse the data when you read it back and convert the string back into separate Flash variables.

As I mentioned, it might be easier to use the INIFile or store your data in XML format because Flash has support for converting XML files to and from strings.