PDA

View Full Version : save game in flash projector


hsing
04-30-2003, 03:55 AM
Hi there,

I have a game that made in flash5. In the game, there are some items on the menu bar, when user click on an item, the item will appear on the stage, then the user can resize, move, rotate the item on the stage. you can see the game here:
http://www.thecomputerstudio.com/maggie/interactive/game.html
Everything works fine, however, I need to save the game, so the user can play later. I had tried use FS command save to the hard drive but it's not working. The text file did write a basic line and save to c drive, but it is not all.

* when the user click on an item, it is using attachmovie command.
* double click on the item on the stage will launch a control panel
* the game will be saved in a projector file but not a swf file
* I am using windows 2000

I am new to action scripting, and I have beed searched for few days and couldn't get a right answer, hopefully if somebody can help. Thanks in advance.

EsChEr
04-30-2003, 04:31 AM
the problem is saving the file or doing something with what you have in the file?
for the first one I recommend the use of flash studio pro or swf studio, the fscommands with exec are not a very good practice and are detected as virus by some av software.
For the second option it would be necesary to see the fla directly

hsing
04-30-2003, 04:41 AM
The game works fine, I just need to save the game. Every piece was create with attachmovie command, and user will move and resize it around the stage. I need them to be able to save the position, size...when the user reopen the project next time. she can continue to play. You can go to the link I provide and see how it goes.


I don't know where to start to write the variable, can you tell me something more or some resources? Most of resource I found are only for simple text fields, or highest score.

Thank you.

EsChEr
04-30-2003, 05:00 AM
well, I would recommend saving it all to a string, taking objects piece type, _x, _y, _width and _height and formating them like this:
man1^100^89^150^200@desk2^234^132^326^457@etc...
separate each piece with @ and each data with ^, then you save it to a file, when the user reopens this then you load the data from the txt and start your routine which woluld go something like:myData = savedString.split("@");
for (i=0; i<myData.length; i++) {
j++;
myParameters = myData[i].split("^");
this.attachMovie(myParameters[0], "newClip"+j, j);
this["newClip"+j]._x = myParameters[1];
this["newClip"+j]._y = myParameters[2];
this["newClip"+j]._width = myParameters[3];
this["newClip"+j]._height = myParameters[4];
} I have no way of cheking this code, so I hope at least you get the idea from it, savedString would be the data from your txt

hsing
04-30-2003, 05:15 AM
This makes sense to me. But I still need more directions to start -


the flash script is very easy on this game, each piece is a button and contains script like this :

on (press) {
_root["general"].attachMovie("man1", "man1"+level, level);
_root["man1"+level]._x = 60;
_root["man1"+level]._y = 110;
level++;
}


the item will appear on the stage but then it can be moved using start drag command. so It's not only save the items but also its position, size...

I am new to scripting, and will need more step by step help, thanks a lot!


;)

hsing
04-30-2003, 05:26 AM
Hi, I reviewed you code again, then I found what my questions is now -

1.since I have no way to know how many men, cars, trees... and all the proporties need to be saved, then how to write the code to saved all infomations?

2. the file is saved as text file in harddrive or somewhere? what is the command to save the file?



thanks

EsChEr
04-30-2003, 05:40 AM
ok, here goes, thissolution is kind of a patch because you naming conventions are not the best.
First create an object and an array in rootfunction piece(mc, name){
this.mc = mc;
this.name = name;
}
myPieces = new Array();
then add this lyne to your buttons with it's obvious adjusments_root.myPieces[_root.myPieces.length] = new _root.piece(_root["man1"+level], "man1");
and finally when you want to create the string to save it execute this codefor (j=0; j<myPieces.length; j++) {
str4Save += myPieces[j].name+"^";
str4Save += myPieces[j].mc._x+"^";
str4Save += myPieces[j].mc._y+"^";
str4Save += myPieces[j].mc._width+"^";
str4Save += myPieces[j].mc._height+"@";
} and now for the saving the file part there is no... mmm ... natural way of doing it, flash cannot do it directly, that's why I suggested cheking out flash studio pro or swf studio, there's a way of doing it with fscommand exec which I've used and must have around somewhere, but not right now, maybe tomorrow

hsing
04-30-2003, 05:53 AM
Thanks, I will try it. If it's not working, I might have to bother you again!

Caimin
04-30-2003, 08:19 AM
Maybe I'm missing something here, but why can't you publish the projector as Flash 6 and use Shared Objects to save the game data?

EsChEr
04-30-2003, 12:55 PM
haha, you are right I never asked why flash 5?

Ricod
04-30-2003, 01:34 PM
Probably because he doesn't have Flash 6 ? Buying an upgrade every year or so is pretty expensive, especially if you're a student and don't study an IT related course.

hsing
04-30-2003, 08:52 PM
Hi, I am back.

I am still using flash5 but you say that flashMX can do much easier with this job?

EsChEr
04-30-2003, 10:36 PM
forget easier, it CAN do it, flash 5 can't