2 Replies Latest reply on May 7, 2008 11:21 PM by Newsgroup_User

    use a Shared Object in a game to store pairs player_name - player

    Level 7
      If I want to use a Shared Object in a game for a local computer to store
      pairs player_name - player_score (a string and a number) what would be the
      best approach to push the data in and retrieve them out as a table?
      Flash Help says that the properties created in a SO can enumerated in a
      for..in loop - how do I use this?


        • 1. Re: use a Shared Object in a game to store pairs player_name - player
          clbeech Level 3
          I usually use an array and objects to store the pair or more stats, then store the array in the SO. it goes something like this:
          • 2. Re: use a Shared Object in a game to store pairs player_name - player
            Level 7
            thank a lot
            "clbeech" <webforumsuser@macromedia.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
            ÓÌÅÄÕÀÝÅÅ: news:fvsrst$qkp$1@forums.macromedia.com...
            > I usually use an array and objects to store the pair or more stats, then
            store
            > the array in the SO. it goes something like this:
            >
            >
            > var so = SharedObject.getLocal('mygame', '/');
            > var scores = [ ];
            > for(var i=0; 1<10; i++) {
            > var obj = {n:' ', s:o};
            > scores.push(obj);
            > }
            >
            > function updateScores() {
            > if(so.data.highscores == undefined) {
            > so.data.highscores = scores;
            > }else{
            > scores = so.data.highscores;
            > }
            > }
            >
            > function saveScore() {
            > var obj = {n:name_ti.text, sc:playerScore}
            > scores.push(obj);
            > scores.sortOn('s', Array.NUMERIC | Array.DESCENDING);
            > if(scores.length>10) scores.pop();
            >
            > so.data.highscores = scores;
            > so.flush();
            > setScoreboard();
            > }
            >
            > function setScoreboard() {
            > updateScores();
            > scores.sortOn('s', Array.NUMERIC | Array.DESCENDING);
            > for(var i=1; i<scores.length+1; i++) {
            > this['name_'+i].text = scores .n;
            > this['score_'+i].text = scores
            .s;
            > }
            > }
            >
            > setScoreboard(); //initialize the board
            >
            > save_btn.onPress = function() {
            > saveScore(); //save the score input
            > }
            >