A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Saving files?

  1. #1
    Member
    Join Date
    Mar 2004
    Location
    Utah
    Posts
    97

    Saving files?

    I wish to make it possible for the user to save a file to their cookies and load it up later. Does it involve PHP or other SSLs to do this? If so, where can I find a tutorial? Otherwise, where can I find a tutorial? Heh, thanks

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    I guess you want Shared Objects:

    http://www.macromedia.com/cfusion/kn...D=963068dc439b
    gparis

  3. #3
    Member
    Join Date
    Mar 2004
    Location
    Utah
    Posts
    97
    Umm...no. lol. I only want a very primitive Save Game function.

  4. #4
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    From what I've read (the link gparis posted, in fact ), "Shared Objects" are the "cookies" of the Flash program. Are you planning on making the save game function for your drag and drop game?

  5. #5
    Member
    Join Date
    Mar 2004
    Location
    Utah
    Posts
    97
    Heh, nope. The drag and drop code was for a part of my massive tutorial (I know, I know...embarrasing to ask for help with a tutorial! But it is helping ME learn as well!)

    This save game is for an RPG which I am working on. I want to push my own limits, since I'm nowhere near pushing Flash's limits!

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Either you use the Shared Object to save on the user's HD (flash cookies) or you use PHP to save on a server. Flash cannot "save" variables on a server or user HD by itself. Flash5 (PC only) was able to save on a user's HD but Macromedia removed the option for security reasons.

    gparis

  7. #7
    Member
    Join Date
    Mar 2004
    Location
    Utah
    Posts
    97
    Well, that's sad! Ok, the ultimate goal is to submit on NG, Flashkit, and other portal sites. What can I do when all I get to upload is a SWF? I also have a server of my own to use if necesarry. Basically I want to save a cookie to their HD that has about 20 variables in it.

  8. #8
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Okay, it's like this...

    First you create the shared object, which will act like a "cookie".

    code:

    var my_so:SharedObject = SharedObject.getLocal("myCookie");



    Now, lets say you have a variable for the users name (we'll call it "userName") and a variable that keeps track of the users score (we'll call that "userScore"). To add these variables to the shared object, you'd use:

    code:

    my_so.data.userScore = userScore;
    my_so.data.userName = userName;



    Now, lets say you have a textbox on the first frame of your movie that you'd like to have display the users name if he/she has been to the site before (lets call the text box "nameBox"). You'd use:

    code:

    nameBox.text = my_so.data.userName;


  9. #9
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    with php you could use something like
    Code:
    <?PHP
    $p = $_POST['p'];
    $w = $_POST['w'];
    $v = "player: ".$p.", score: ".$w."\n";
    $f = fopen("scores.txt", "a+");
    fwrite($f, $v);
    fclose($f);
    ?>
    the php would be looking to receive two variables via the 'post' method: p and w. someloadvarsobject.sendAndLoad("scores.php", bleh, "POST") will do it. here's a quick sample.
    code:
    var fields = new Array("player", "score");
    var tfo = new TextFormat("Tahoma", 11, 0x000000, true);
    for (var i=0;i<fields.length;i++) {
    this.createTextField(fields[i], i, i*200, 0, 180, 18);
    this[fields[i]].type = "input";
    this[fields[i]].text = fields[i];
    }
    this.score.onKillFocus = function() {
    l = new LoadVars();
    l.p = _level0.player.text;
    l.w = _level0.score.text;
    l.sendAndLoad("scores.php", l, "POST");
    };

    make sure you set the scores.txt file to all writable, and the scores.php file to all executable.

    hth gl.

  10. #10
    Member
    Join Date
    Mar 2004
    Location
    Utah
    Posts
    97
    Thanks both, I would prefer the shared object method since I would prefer not to use my own space (as it changes frequently due to bad servers, sadly enough ) Thanks though Moagrius.

    But, my question would be directed towards Quixx: It is an RPG, is it possible to store variables like Weapon=, Shield=, etc? And if I name the vars the same thing, it should be easier to just place them back in when they load a game, no?

    Thanks so much for helpin me dude, you rule

  11. #11
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Hi,
    I'm not sure I fully understand what you are asking? You can store all sorts of information into a shared object (Number, Boolean, Arrays, etc...). But you'll always have to point to the shared object directly to store the information:

    code:

    var my_so:SharedObject = SharedObject.getLocal("myCookie");
    Shield="IronShield"
    my_so.data.Shield = Shield;


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