A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: what's a simple way to save variables?

  1. #1
    Junior Member
    Join Date
    Feb 2005
    Location
    not here.
    Posts
    8

    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?

  2. #2
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    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..

  3. #3
    Junior Member
    Join Date
    Feb 2005
    Location
    not here.
    Posts
    8
    thanks! i'll test it out tomorrow cuz i'm too tired right now...

  4. #4
    Junior Member
    Join Date
    Feb 2005
    Location
    not here.
    Posts
    8
    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?

  5. #5
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    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.

  6. #6
    Junior Member
    Join Date
    Feb 2005
    Location
    not here.
    Posts
    8
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center