A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Automatically Flushed Shared Objects

  1. #1
    Axis Games Djugan's Avatar
    Join Date
    Oct 2003
    Posts
    238

    Automatically Flushed Shared Objects

    Hey guys, quick question.

    I'm fine-tuning the save feature of my rpg game, and I noticed an unfortunate feature (for me, at least) of Shared Objects. Whenever you close the application where the Shared Object was created, it automatically flushes (writes) the data to the disk. It's a problem because I want the game saved only when a player visits the Innkeeper in the city. I've only tested this offline because my website is blocked where I am currently. My question is: will the auto-flush feature occur when the .swf is played in a browser online, too? And if so, is there anything that I can do to prevent this from happening.

    Thanks

  2. #2
    Store the variables and dont update the sharedobject until they visit the inn?

  3. #3
    Axis Games Djugan's Avatar
    Join Date
    Oct 2003
    Posts
    238
    I don't. There's a save button that pops up when you talk with the Innkeeper, and that's the only time I ever write the data to the shared object.

    The problem is: Let's say you save and go back out into the work and keep fighting. You buy some gear that you decide a few minutes later you didn't want to buy, so you close out the window. The flush() function is called as soon as the window is closed and it's saving all of the gear that you bought.

  4. #4
    Axis Games Djugan's Avatar
    Join Date
    Oct 2003
    Posts
    238
    The way I have the save feature set up is, when you click "save" it writes a bunch of data.vars that correspond to the variables that I have in the game.

    For example:
    //on save
    mySO.data.level = _root.level;

    //on load
    _root.level = mySO.data.level;


    After looking at a lot of trace functions and such, it appears that the data in the Shared Object is being linked to the data in the game. I traced the mySO.data variables and they are being updated in the game as their corresponding variables are being updated, even though I never tell them to update (mySO.data.level is being changed whenever _root.level changes).

    Again, I'm not sure if this is a function of playing the game offline. If this won't happen when the game is played online then it doesn't matter. I just don't have a lot of experience with Shared Objects to know. Any help?

  5. #5
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    I don't know, maybe you have to use the close() function after you flush? Maybe that prevents it from saving when you close the browser.

  6. #6
    Axis Games Djugan's Avatar
    Join Date
    Oct 2003
    Posts
    238
    Unfortunately there is no close() function for the Shared Objects class. My guess is that this is occuring because the .swf exists on a local level. I'm going to try it online and if all else fails, I'll just add the true parameter to the getLocal() function so it only reads it from a http location.

    Thanks for the help, though.

  7. #7
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    Okay it looks like close() is only in AS3, and it only applies to server shared objects.

    I'm thinking it sounds like you need to use another variable to store the variables for your game session. But I think you might run into the same problem like that so maybe you can try this...

    PHP Code:
    //on load
    _root.level mySO.data.level
    When you set the level variable to the sharedObject, you're creating a reference to the sharedObject.

    So if you do something like this...
    PHP Code:
    _root.level 5
    it acts as a shortcut to this...
    PHP Code:
    mySO.data.level 5
    And when you close the browser it automatically flushes with the variable.

    I'm thinking you can try copying the value of mySO.data.level without making a reference. So something like...

    _root.level = Number(mySO.data.level);
    Which will give you the number value stored in the sharedObject without giving a reference to it. I'm not sure if casting as a number works exactly like that in AS2 though. But you can do it with String() as well.

    In addition to that, you'd want to do the same for the save function as well. Since that probably creates a reference as well. So..

    PHP Code:
    //on save
    mySO.data.level _root.level
    becomes

    PHP Code:
    //on save
    mySO.data.level Number(_root.level); 
    Last edited by Son of Bryce; 11-07-2008 at 04:05 PM.

  8. #8
    Axis Games Djugan's Avatar
    Join Date
    Oct 2003
    Posts
    238
    That makes a lot of sense. I never thought about the fact that I was creating an alias to the object.

    But I think you're right, if I typecast the data to a non-object when I'm loading the game, you would think that it wouldn't set the variable equal to the memory location of the object, but rather what the object contains. I'll give it a shot.

    Thanks so much!

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