1

I've looked everywhere for this answer..but I am not quite sure on how to do it exactly...

I am making a Flash Game using Flash AS3...

I need options where user can save and load their progress..

can somebody give a step by step on how to do this please? I am very new to actionscript...

usually other tuts shows u how to save certain variables

tailedmouse
  • 365
  • 3
  • 16
  • In Flash we usually save data by sending it to a server, and loading it as needed. It's just like any other web application. Web apps can save some data in cookies, and in Flash there is something similar called a SharedObject. But you will probably find that most Flash games use a server for this sort of thing. – Sunil D. Dec 30 '12 at 02:05
  • so there is no practical way to save a game progress? but is there a way? – tailedmouse Dec 30 '12 at 03:23
  • I mentioned two ways to persist data: send the data to a server and using a SharedObject (which is like a cookie). – Sunil D. Dec 30 '12 at 03:28
  • oh my bad i thought they were both the same umm for say if i use a sharedobject for example can u present me an example where it can actually save the whole progress...because everything on the net I saw was saving variables...I am sorry if it's a dumb question just starting out... – tailedmouse Dec 30 '12 at 03:35
  • Can you define "progress" in your words? What is an example of "progress" ? – mitim Dec 30 '12 at 03:43
  • oh I jsut mean what ever happened in the game so far it just saves all that so next time when u load it picks it up from there.. – tailedmouse Dec 30 '12 at 03:55
  • can you give a specific example of something that would happen in a game you're making? – mitim Dec 30 '12 at 04:35
  • alright..there are 8 stages in the game..each time the user clears a level he should have an option to save the game... so next time when he comes back he can pick it up from that same level again.... – tailedmouse Dec 30 '12 at 04:49
  • okay, so you have a 'stage level' value. This can be a number from 0 to 7 (or 1 to 8). This value would be stored in a variable -which you would save using methods mentioned above. – mitim Dec 30 '12 at 04:53
  • ah i see what u mean so i attach this value to the last event that happens and that causes it to save... OMG THANKS ALOT....but for say if I want let them save in middle of a level what would I do?? – tailedmouse Dec 30 '12 at 04:57
  • I mean saving at their will not really like a checkpoint... – tailedmouse Dec 30 '12 at 05:04

2 Answers2

2

Cookies!

Lucky us it's very simple. Unlucky us it's not obvious how it's done:

// have that referenced all the time:
var cookies: SharedObject = SharedObject.getLocal("myGameData");

// start saving
cookies.data.progress = 50;
cookies.data.lives = 5;
cookies.data.anyRandomVariable = "my name or something";
cookies.flush();
// now it's saved

// start loading
var progress: Number = cookies.data.progress;
var lives: int = cookies.data.lives = 5;
var anyRandomBlah: String = cookies.data.anyRandomVariable;
// now it's loaded
n4pgamer
  • 624
  • 1
  • 6
  • 20
1

(following the comments above...)

Yes, pretty much along those lines. I was asking questions to try to get you to see that you do actually have variables/data which you'd save. =b

If you want to save in the middle of the level, it is up to you... I don't know how you've designed your game, but basically you can write the saving code to trigger whenever you want based on any conditions you want.

For saving in the middle of levels, since you are handling the saving and loading you could try having a value like level "7.5" or whatever notation you want to indicate a level that is partway done. Or just use whole numbers like 750 and treat it as a percentage (level 7 at 50% done). And so forth. It's up to you.

A very similar question has been asked how to save a current frame value using a SharedObject. In your case, replace 'current frame' with whatever values you want to save:

Actionscript 3 saving currentframe location to local hard drive?

Community
  • 1
  • 1
mitim
  • 3,169
  • 5
  • 21
  • 25
  • YOSH!!! thx a lot for ur help i want to give this a go as soon as possible...u made my life easier by a mile by not giving me the answer right away!!!! – tailedmouse Dec 30 '12 at 05:09
  • hi i tired it an i kind of didn't get on hwo to do it sorry... can u explain it to me??I did just as the link u sent me showed.. i changed the variable username with the variable i created in the game and also the nameField.text part but it is showing that access to undefined property namefield?? I am sorry i am very new to this can u explain me a bit in step by step.. I already tried reading the document of sharedobject but still it isn't quite clear to mee.. – tailedmouse Dec 30 '12 at 21:28
  • Well, "nameField" was just a textfield was just something someone else was using in their own code. This probably does not apply to you. The other parts, creating the shared object, accessing its data property are the main parts. – mitim Dec 31 '12 at 01:22
  • oh I see so i have this variable i want to save which is called gamesavepoint and.. did this with it – tailedmouse Dec 31 '12 at 01:31
  • savestuff = SharedObject.getLocal("saved_progress");; savestuff.data.gamesavepoint = – tailedmouse Dec 31 '12 at 01:31
  • oops sorry it keeps sending it by accident my mistake... so.. this is the code I used...savestuff = SharedObject.getLocal("saved_progress"); savestuff.data.gamesavepoint = what should i include after the equal ? – tailedmouse Dec 31 '12 at 01:32
  • I don't think this is really the spot for a discussions...as it keeps saying so. =b But the answer to your question is in my answer -whatever value you want to use to represent the progress/levels in your game (it looks like you are on your way to getting it figured out though). – mitim Dec 31 '12 at 02:50
  • I JUST MADE IT SAVE!!! YUPIEEE..... thx a lot for ur help.. I created a object and parented to every variable tht existed and had a save button linked to another actionscript file that had the sharedobject command. well it traced it saved but how do i exactly check it?and yah this is not a good place to talk i am not too familiar with this website can i message u somehow? – tailedmouse Dec 31 '12 at 04:47