4 Replies Latest reply on Jul 29, 2009 12:10 PM by jimmyoneshot

    Saving changes to a tilelist using the sharedObeject() method

    jimmyoneshot Level 1

      Yesterday I asked on here for a simple way to allow users to save changes they make to an application at the click of a save button and was given an excellent suggestion which was the use of the shared object method which stores saved data even after an application is closed and reopeneded.

       

      However I am struggling to get this to work with changes to tilelists. In my application I have a text area in which the user can enter their name, A left hand tilelist populated by details from an array collection from which the user can then drag items into the right hand tilelist, a reset button that resets the tilelist and changes to the tilelists after the user has dragged and dropped items, and a save button which once clicked should save all changes to the application but at the moment it only saves the text a user has entered into the text area.

       

      What I want is when the user drags an item / some items from the left tilelist to the right tilelist and clicks the save button any changes to both tilelists are also saved eg if the user drags an item from left to right then clicks save, the next time they close and reopen the app that item will no longer be in the left tilelist and will be in the right one.

       

      Can anybody perhaps edit my code for me so that this saves the tilelists too as I'm completely clueless on where to start on this.

       

      Here is the code for my application:-

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initprofile1SO()"

      >

       

       

       

      <mx:Script>

      <![CDATA[

       

       

       

      import

      mx.collections.*;

       

       

       

      private function profile1NewsAndSportReset():void

      {

      profile1NewsAndSportAddLinksTilelist.dataProvider =

       

      new

      ArrayCollection([

      {link:

       

      "www.bbcnews.com", label:"BBC News"

      },

      {link:

       

      "www.itv.com/", label:"ITV"

      },

      {link:

       

      "www.skynews.com", label:"Sky News"

      },

      ]);

       

      profile1NewsAndSportLinkChoice.dataProvider =

       

      new

      ArrayCollection([]);

      }

       

      ]]>

       

       

      </mx:Script>

       

       

       

      <mx:Script>

      <![CDATA[

       

       

      import

      flash.net.SharedObject;

       

       

       

      public var

      profile1NameSO:SharedObject;

       

       

       

      private function initprofile1SO():void

      {

      profile1NameSO = SharedObject.getLocal(

       

      "profile1Name"

      );

       

       

      if

      (profile1NameSO.size > 0)

      Profile1NameEntry.text=profile1NameSO.data.name;

      }

       

       

       

      private function saveProfile1(event:MouseEvent):void

      {

      profile1NameSO.data.name = Profile1NameEntry.text;

      profile1NameSO.flush();

      }

       

      ]]>

       

       

      </mx:Script>

       

       

       

      <mx:TextInput id="Profile1NameEntry" maxChars="10" width="113" fontSize="10" x="5" y="77.5"

      />

       

       

       

      <mx:Button click="profile1NewsAndSportReset()" id="reset" label="Reset" y="5" height="25" x="5"

      />

       

       

       

      <mx:TileList id="profile1NewsAndSportLinkChoice" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="292" width="650" top="5" left="521" columnCount="5" rowHeight="145" columnWidth="125" backgroundColor="#000000" color="#FFFFFF"/>

       

       

       

      <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="419" width="385" top="5" left="128" columnCount="3" rowHeight="145" columnWidth="125" backgroundColor="#000000" color="#FFFFFF"

      >

       

       

      <mx:dataProvider>

       

       

      <mx:Array>

       

       

      <mx:Object link="www.bbcnews.com" label="BBC News"

      />

       

       

      <mx:Object link="www.itv.com/" label="ITV"

      />

       

       

      <mx:Object link="www.skynews.com" label="Sky News"

      />

       

       

      </mx:Array>

       

       

      </mx:dataProvider>

       

       

      </mx:TileList>

       

       

       

      <mx:Button click="saveProfile1(event)" id="save" label="Save Changes" x="5" y="38" width="113" height="25.5"

      />

       

      </mx:Application>

        • 1. Re: Saving changes to a tilelist using the sharedObeject() method
          Gregory Lafrance Level 6

          If this post answers your question or helps, please mark it as such.

           

          Here is the answer:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            layout="absolute" creationComplete="initprofile1SO();">
            <mx:Script>
              <![CDATA[
                import mx.collections.*;
                import flash.net.SharedObject;

                public var profile1NameSO:SharedObject;

                private var addLinksFullAC:ArrayCollection = new ArrayCollection([
                  {link: "www.bbcnews.com", label:"BBC News"},
                  {link: "www.itv.com/", label:"ITV"},
                  {link: "www.skynews.com", label:"Sky News"}
                ]);
               
                private var addLinksAC:ArrayCollection = new ArrayCollection([
                  {link: "www.bbcnews.com", label:"BBC News"},
                  {link: "www.itv.com/", label:"ITV"},
                  {link: "www.skynews.com", label:"Sky News"}
                ]);

                private function profile1NewsAndSportReset():void{
                  resetAC();
                  profile1NewsAndSportAddLinksTilelist.dataProvider
                    = addLinksAC;

                  profile1NewsAndSportLinkChoice.dataProvider = new ArrayCollection([]);
                }
               
                private function resetAC():void{
                  addLinksAC.removeAll();
                  for each(var obj:Object in addLinksFullAC){
                    addLinksAC.addItem(obj);
                  }
                }
               
                private function initprofile1SO():void{
                  profile1NameSO = SharedObject.getLocal("profile1Name");

                  if(profile1NameSO.size > 0){
                    if(profile1NameSO.data.name){
                      Profile1NameEntry.text=profile1NameSO.data.name;
                    }
                    if(profile1NameSO.data.addList){
                      var addList:Array = profile1NameSO.data.addList.split(",");
                      var tempAC1:ArrayCollection = new ArrayCollection();
                      for each(var str:String in addList){
                        for each(var obj1:Object in addLinksAC){
                          if(str == obj1.label){
                            tempAC1.addItem(obj1);
                            continue;
                          }
                        }
                      }
                      if(tempAC1.length > 0){
                        profile1NewsAndSportAddLinksTilelist.dataProvider = tempAC1;
                      }           
                    }else{
                      profile1NewsAndSportAddLinksTilelist.dataProvider
                        = addLinksAC;            
                    }
                    if(profile1NameSO.data.choiceList){
                      var choiceList:Array = profile1NameSO.data.choiceList.split(",");
                      var tempAC2:ArrayCollection = new ArrayCollection();
                      for each(var str2:String in choiceList){
                        for each(var obj2:Object in addLinksAC){
                          if(str2 == obj2.label){
                            tempAC2.addItem(obj2);
                            continue;
                          }
                        }
                      }
                      if(tempAC2.length > 0){
                        profile1NewsAndSportLinkChoice.dataProvider = tempAC2;
                      }           
                    }
                  }else{
                      profile1NewsAndSportReset();
                  }
                }

                private function saveProfile1(event:MouseEvent):void{
                  profile1NameSO.data.name = Profile1NameEntry.text;
                  var addList:String = "";
                  for each(var obj1:Object in
                    profile1NewsAndSportAddLinksTilelist.dataProvider){
                    addList += obj1.label + ",";
                  }
                  profile1NameSO.data.addList = addList;
                  var choiceList:String = "";
                  for each(var obj2:Object in
                    profile1NewsAndSportLinkChoice.dataProvider){
                    choiceList += obj2.label + ",";
                  }
                  profile1NameSO.data.choiceList = choiceList;
                  profile1NameSO.flush();
                }
              ]]>
            </mx:Script>
            <mx:TextInput id="Profile1NameEntry" maxChars="10"
              width="113" fontSize="10" x="5" y="77.5"/>
            <mx:Button click="profile1NewsAndSportReset()" id="reset"
              label="Reset" y="5" height="25" x="5"/>

            <mx:TileList id="profile1NewsAndSportLinkChoice" fontWeight="bold"
              dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="292"
              width="650" top="5" left="521" columnCount="5" rowHeight="145"
              columnWidth="125" backgroundColor="#000000" color="#FFFFFF"/>

            <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold"
              dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="419"
              width="385" top="5" left="128" columnCount="3" rowHeight="145" columnWidth="125"
              backgroundColor="#000000" color="#FFFFFF"/>
            <mx:Button click="saveProfile1(event)" id="save" label="Save Changes"
              x="5" y="38" width="113" height="25.5"/>
          </mx:Application>

          1 person found this helpful
          • 2. Re: Saving changes to a tilelist using the sharedObeject() method
            jimmyoneshot Level 1

            Hi Greg. That's fantastic. The only problem is that it seems if I drag ALL of the 3 items from the left tilelist to the right and then click save after reloading the app the dataprovider of the left hand tilelist is back to normal again i.e. both tilelists then have 3 items in them. Is there any way to fix this so that if the user drags all the items from the "source" left hand tilelist to the right tilelist and clicks save the left one will then be empty after reload?

             

            Thanks again for all your help

            • 3. Re: Saving changes to a tilelist using the sharedObeject() method
              Gregory Lafrance Level 6

              If this post answered your question or helped, please mark it as such.

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute" creationComplete="initprofile1SO();">
                <mx:Script>
                  <![CDATA[
                    import mx.collections.*;
                    import flash.net.SharedObject;
                    public var profile1NameSO:SharedObject;
                    private var addLinksFullAC:ArrayCollection = new ArrayCollection([
                      {link: "www.bbcnews.com", label:"BBC News"},
                      {link: "www.itv.com/", label:"ITV"},
                      {link: "www.skynews.com", label:"Sky News"}
                    ]);
                    
                    private var addLinksAC:ArrayCollection = new ArrayCollection([
                      {link: "www.bbcnews.com", label:"BBC News"},
                      {link: "www.itv.com/", label:"ITV"},
                      {link: "www.skynews.com", label:"Sky News"}
                    ]);
                    private function profile1NewsAndSportReset():void{
                      resetAC();
                      profile1NewsAndSportAddLinksTilelist.dataProvider 
                        = addLinksAC;
                      profile1NewsAndSportLinkChoice.dataProvider = new ArrayCollection([]); 
                    }
                    
                    private function resetAC():void{
                      addLinksAC.removeAll();
                      for each(var obj:Object in addLinksFullAC){
                        addLinksAC.addItem(obj);
                      }
                    }
                    
                    private function initprofile1SO():void{
                      profile1NameSO = SharedObject.getLocal("profile1Name");
                      if(profile1NameSO.size > 0){
                        if(profile1NameSO.data.name){
                          Profile1NameEntry.text=profile1NameSO.data.name;
                        }
                        if(profile1NameSO.data.addList){
                          if(profile1NameSO.data.addList != "empty"){
                            var addList:Array = profile1NameSO.data.addList.split(",");
                            var tempAC1:ArrayCollection = new ArrayCollection();
                            for each(var str:String in addList){
                              for each(var obj1:Object in addLinksAC){
                                if(str == obj1.label){
                                  tempAC1.addItem(obj1);
                                  continue;
                                }
                              }
                            }
                            if(tempAC1.length > 0){
                              profile1NewsAndSportAddLinksTilelist.dataProvider = tempAC1;
                            }            
                          }
                        }
                        if(profile1NameSO.data.choiceList){
                          var choiceList:Array = profile1NameSO.data.choiceList.split(",");
                          var tempAC2:ArrayCollection = new ArrayCollection();
                          for each(var str2:String in choiceList){
                            for each(var obj2:Object in addLinksAC){
                              if(str2 == obj2.label){
                                tempAC2.addItem(obj2);
                                continue;
                              }
                            }
                          }
                          if(tempAC2.length > 0){
                            profile1NewsAndSportLinkChoice.dataProvider = tempAC2;
                          }            
                        }
                      }else{
                          profile1NewsAndSportReset();
                      }
                    }
                    private function saveProfile1(event:MouseEvent):void{
                      profile1NameSO.data.name = Profile1NameEntry.text;
                      var addList:String = "";
                      if(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).length > 0){
                        for each(var obj1:Object in 
                          profile1NewsAndSportAddLinksTilelist.dataProvider){
                          addList += obj1.label + ",";
                        }
                      }else{
                        addList = "empty";
                      }
                      profile1NameSO.data.addList = addList; 
                      var choiceList:String = "";
                      for each(var obj2:Object in 
                        profile1NewsAndSportLinkChoice.dataProvider){
                        choiceList += obj2.label + ",";
                      }
                      profile1NameSO.data.choiceList = choiceList;
                      profile1NameSO.flush();
                    }
                  ]]>
                </mx:Script>
                <mx:TextInput id="Profile1NameEntry" maxChars="10" 
                  width="113" fontSize="10" x="5" y="77.5"/>
                <mx:Button click="profile1NewsAndSportReset()" id="reset" 
                  label="Reset" y="5" height="25" x="5"/>
                <mx:TileList id="profile1NewsAndSportLinkChoice" fontWeight="bold" 
                  dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="292" 
                  width="650" top="5" left="521" columnCount="5" rowHeight="145" 
                  columnWidth="125" backgroundColor="#000000" color="#FFFFFF"/>
                <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold" 
                  dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="419" 
                  width="385" top="5" left="128" columnCount="3" rowHeight="145" columnWidth="125" 
                  backgroundColor="#000000" color="#FFFFFF"/>
                <mx:Button click="saveProfile1(event)" id="save" label="Save Changes" 
                  x="5" y="38" width="113" height="25.5"/>
              </mx:Application>