6 Replies Latest reply on Apr 3, 2008 1:05 PM by MayLam18

    Shared Object question

    May 2008 Level 1
      Hi guys,

      Do we have Shared Object Collection in Flex 3 ? For example, I want to store the following data into a share object collection:

      {english} Add, 1
      {spanish} Add, 2

      {english} Update, 1
      {spanish} Update, 2

      and so on....

      Now when the flex 3 application is load. then a user enters 1 or 2. If enter 1, then the application will display {english} Add and {english} Update.

      Can I do this in shared object in flex 3?

      Thanks,

      May
        • 1. Re: Shared Object question
          Connect Studios
          //set the information...
          var shrdObj:SharedObject = SharedObject.getLocal("mySharedObject");
          shrdObj.data.Add = {1:"english", 2:"spanish"};
          shrdObj.data.Update = {1:"english", 2:"spanish"};

          //get the information
          public function getAddLang(choiceNum:int):String
          {
          var shrdObj:SharedObject = SharedObject.getLocal("mySharedObject");
          var myLanguage:String = "";
          if(shrdObj.data.Add != null){
          myLanguage = shrdObj.data.Add[choiceNum];
          }
          return myLanguage;
          }

          public function getUpdateLang(choiceNum:int):String
          {
          var shrdObj:SharedObject = SharedObject.getLocal("mySharedObject");
          var myLanguage:String = "";
          if(shrdObj.data.Update != null){
          myLanguage = shrdObj.data.Update[choiceNum];
          }
          return myLanguage;
          }



          try that.
          • 2. Re: Shared Object question
            May 2008 Level 1
            Hi,

            Thanks for your help! Your code is nice and neat. But it is not exactly what I am looking for. My next question is can I store the XMLList into a shared object ?

            Thanks,

            May
            • 3. Re: Shared Object question
              Connect Studios Level 1
              Yeah, just store it as an xml string and convert it back to XML when you get it back.

              That's what XML is for!!!! ;)
              • 4. Re: Shared Object question
                May 2008 Level 1
                That's great that I can store the XMLList as xml string!

                If possible, please give me some code. Thanks for your help again!

                May
                • 5. Re: Shared Object question
                  Connect Studios Level 1
                  shrdObj.data.xml = myXMLList.toXMLString();

                  //get it back to an XMLList...

                  var xml:XML = new XML("<root>"+shrdObj.data.xml+"</root>");
                  //the root tag insures that the xml is valid.
                  var xmlList:XMLList = xml.children();


                  I used that method to make the XMLList again because I don't know if the following will work...

                  var xmlList:XMLList = new XMLList(shrdObj.data.xml);
                  • 6. Re: Shared Object question
                    MayLam18 Level 1
                    Hi,

                    Thank you very much for your code!

                    I will try your code later.

                    May