hi, I am trying to add a save and load feature to my fla.
Currently on the same frame, I have; Load, Save, Delete.
The content seems to save the array alright, but when I save "game one", and reload game one only is there. Then when I save "game two", game one and two are there. But if i reload, some random ones are added, from previous although I have them deleted..
Also, I wondering how I would sort the shared objects.
I am using localInfo = SharedObject.getLocal("savedgame"+e);
so say i add
SharedObject.getLocal.savedgame0
and the info in the array [0][0] is "Eric"
then i add
SharedObject.getLocal.savedgame1
info: "Bob"
SharedObject.getLocal.savedgame2
"Ryan"
when I reload it will say
bob
ryan
ryan
Basically I have a feeling that
localInfo = SharedObject.getLocal("savedgame"+my_list.selected Index);
localInfo.clear();
isn't working right. But when I performed a traced it said undefined..
But then It messes up
Any help would be greatly appreciated, And after I fix this bug, I will be improving these code and the features then I will share the finished example with every one!
I tried your code, and nothing is happening. I don’t know how this fla. has to be played.
Please give more information and details about your .fla. That is have I to drag the sprites on the stage to save them. Where the data gets stored? How to reuse the saved data?
I am quite new to shared objects, and I will be very thankful to learn more about it.
this info you want to save gets saved in this array
_level0.looptmp = [slot1=["", 0, "dce"]];
when loaded the info goes to
_level0.looptmp2= [slot1=["", "", ""]];
Slot1 is a catagory (actually its another array)
you could do something like this
var currenthealth:Number = 100
_level0.looptmp = [Character=[ChosenGfx=0, currenthealth=currenthealth, maxhealth=maxthealth, currentxphealth=currentxphealth, currenthealthxptolvl=currenthealthxptolvl], Items=[slot1="hat",slot2="gloves",slot3="toy"], Area=[namee="Nolta", xx=5,yy=5,timeday="Monday",timehour="16",timemin=" 10"]];
This one here sets everything blank and can be loaded into here.
_level0.looptmp2 = [Character=[ChosenGfx="", currenthealth="", maxhealth="", currentxphealth="", currenthealthxptolvl=""], Items=[slot1="",slot2="",slot3=""], Area=[namee="", xx="",yy="",timeday="",timehour="",timemin=""]];
then you can for example set things like the characters position
gotoAndStop(_level0.looptmp2[2][0]); (this can be a label namee="name" or a number namee=5)
player._x = _level0.looptmp2[2][1];
player._y = _level0.looptmp2[2][2];
then you set the health
playerhealthcur = _level0.looptmp2[0][1];
and so forth. You can do lots of things
Last edited by brickhouse420; 01-02-2011 at 02:49 PM.
You can use a program like .minerva to view your shared objects (http://blog.coursevector.com/minerva ). FlashDevelop also has a shared object reader within it as well. Being able to look at the Shared Object will probably let you see what's actually going on.
Also, I'm not sure if it makes a difference, but it might be a better idea to store all 3 games within 1 shared object. That's what I typically do. I'm not sure if you're somehow getting mixed it by loading 3 separate Shared Objects.
So save your different games into...
PHP Code:
localInfo.data.game1 = game 1 array; localInfo.data.game2 = game 2 array; localInfo.data.game3 = game 3 array;
Very good idea, and this way I don't have to reload the shared object over and over. But, it seems like any one can navigate to the folder with the shared object and open the file as a text. and basically use that to cheat.
Also, I'm not sure if it makes a difference, but it might be a better idea to store all 3 games within 1 shared object. That's what I typically do. I'm not sure if you're somehow getting mixed it by loading 3 separate Shared Objects.
I agree, a swf should only use one shared object. No need to clutter a users system up with unneeded files.
You may want to look up the flush method of shared object, to force the swf to save. This makes sure the data gets saved, even if there is an unexpected ending of the session.
At the moment you're only putting AS3 native objects (Strings and Arrays) in there, but if in the future you want to save custom classes/objects to yourshared object, check out registerClassAlias.
Thank you guys for the valuable input.
As far as the original question goes, I have fixed it and it runs perfectly.
But I am still wondering how I can protect this data so people don't mess around with it.
Well, you can't really trust anything on the client side. There are libraries that let you encrypt data before saving and decrypt it when reading which will make it harder for people to cheat, but nothing will make it impossible.
I think the Mochi API has something you could use, although they advertise it for use against memory editing utilities I think you can use it for storing data in the Shared Object as well: https://en.mochimedia.com/support/dev_docs#MochiDigits
You can always check it against an MD5 hashsum. Just take some properties which will be stored into the shared object, create a hashsum of it and store that hashsum in the shared object.
When you load the game, take the properties of the shared object and recreate the hashsum. If the hashsum is the same as in the sharedobject, that means that (very probably) the file hasn't been tampered with.
The problem is, that anyone decompling your swf can still find the MD5 check and remove it. But hey, anyone with that skill set, probably won't bother editing just the shared object, as he could as well hack the game itself. The only real way to be safe is to have a call to a server which creates and checks the hashsums, but that may be a bit overkill for a Flash game.
import com.adobe.crypto.MD5;
var salt:String = "your custom salt here";
var toHash:String = property1.toString() + property2.toString();
var hash:String = MD5.hash(toHash + salt); //MD5 is a static class