-
what's a simple way to save variables?
I'm working on a game and it will envolve unlocking stuff like bonus levels and new characters to play as. I figure it would be a good idea to figure out how to save variables so that people don't have to re-unlock everything every time they play. I've looked at a few tutorials here and couldn't get it to work. help please?
-
Special Member
well the simpliest way to save variables mate is to use shared objects... it's also very secure.
you know how to do shared objects? if not check the manual. it's simple..
-
thanks! i'll test it out tomorrow cuz i'm too tired right now...
-
okay I think i can get it to create a shared object, now how do i make it so that it will load the variables i saved from the shared object?
-
Senior Member
Place on the stage a input text box and
give it a variable name "mytext" without the quotes.
Next place 2 dynamic text box on the stage, and name the first one
"mytext1" and the other "mytext2" again without the quotes.
Then place 2 buttons on the stage one button is going to be the save button and the other is the "get" button. The "save" button saves the sharedObject, and "get" button retrieves the sharedObject.
Once you done that, place this code on frame 1 of the timeline.
Code:
myobject = SharedObject.getLocal("myfile");
if (myobject.data.user != null) {
mytext1 = "Welcome Back "+myobject.data.user;
mytext2 = "You've Been Here "+myobject.data.counter+++" times";
} else {
myobject.data.user = "Need Input Please";
myobject.data.counter = 1;
myobject.flush();
}
On the "save" button, not the timeline, put this code
Code:
on (press) {
myobject.data.user = _root.mytext;
myobject.data.counter
myobject.flush();
}
on the "get" button put this code
Code:
on (press) {
_root.mytext1 = "Welcome Back "+_root.myobject.data.user;
_root.mytext2 = "You've Been Here "+_root.myobject.data.counter;
}
Test the movie, and put your name in the input box and press save, then press the get button to see your name
If you don't think you're going to like the answer, then don't ask the question.
-
WOW! it worked! thanks a lot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|