14
« on: October 05, 2021, 08:43:27 pm »
1r2> I haven’t seen your code so I can’t tell what’s wrong.
Generally, you use SharedObject class by declaring variable of it's type, which is by default calling object’s constructor. That is a function which you pass a parameter of stored data set name.
Let’s do it at _root level. You can place it in main timeline key frame which is at _root level so you don’t need to prefix “_root.” pointer before every identifier.
var savedata:SharedObject = SharedObject.getLocal("HTHbetaSave");
This creates object _root.savedata with some functions defined by ShareObject class and named list _root.savedata.data containing all variables that Flash Player could find in HTHbetaSave storage file. These data were loaded at the time the constructor was called, i.e. the game start.
Now you need some load function for load button to assign your game variables with values found in that loaded “savedata” object. Let’s say you have _root.species and _root.dicksize :-) variables defined with some current or default values. Let’s create load function.
saveload = function()
{
if (_root.savedata.data.species != undefined)
{
_root.species = _root.savedata.data.species;
}
if (_root.savedata.data.dicksize != undefined)
{
_root.dicksize = _root.savedata.data.dicksize;
}
}
Note1: You can omit _root. if function is defined at root level, because in Flash function has scope of place where it's defined, not from where it's called.
Note2: You have to always check that variable is defined in save data before overwritting your variable.
Now create a button (see another page of this thread on how to) and define it's action:
loadbutton.onRelease = function()
{
_root.saveload();
}
... or you can paste previous function body into button function directly.
Then you need some save function for save button to get your game variables to savedata object. It's opposite of above, just you don't need to check anything, list items are created simply by assignment.
savesave = function()
{
_root.savedata.data.species = _root.species;
_root.savedata.data.dicksize = _root.dicksize ;
}
You don't need to call anything to actually write the data to the disk, the Flash Player does that automatically on program exit. (Now I actually don't know if AS2 has object destructor functions as it doesn't have a delete operator to explicitly undo data structures and to free memory. If it does, that would be logical place for file save.)
If you want to force Flash Player write data to the disk on button press anyway, you can add statement
_root.savedata.flush();
on the end of that savesave function. But there is no reason to unless your player usually terminates by crashing.
Now create save button calling (or containing) that function and it's done.
I don't guarantee that this works, I didn't test that. It's just a quick idea.