13 Replies Latest reply on Jul 28, 2009 11:18 AM by Gregory Lafrance

    Allowing a user to save changes

    jimmyoneshot Level 1

      I am creating an app that is something similar to this one:-

       

      http://demo.quietlyscheming.com/DragTile/DragDrop.html

       

      However what I want is when a user drags an item from one tilelist into the other tilelist for them to be able to save these changes so that when they close the application and reopen it these changes will still be there i.e. if the top tilelist is tilelist1 and the bottom tilelist is tilelist2 and the user drags a couple of items to tilelist1 TO tilelist2 I want these items to appear in tilelist 2 after the app has been closed and reopened and the items that have been moved NOT to appear in tilelist 1 anymore.

       

      I also want the user to be able to type their name into a text area and save it by clicking a save button so their name will also be shown next time they open the app.

       

      What is the best way to do this? Via xml perhaps? I've used xml to contain data that populates a site in the past but never used it where it allows user's to actually insert data into an xml file. Are there any examples of anything simiar that may help me out?

        • 1. Re: Allowing a user to save changes
          jimmyoneshot Level 1

          Sorry I forgot to add that this application will be an AIR application if that makes any difference because I've heard that Flex apps don't allow user's to write data but AIR apps do.

          • 2. Re: Allowing a user to save changes
            Gregory Lafrance Level 6

            Actually, Flex apps can use SharedObject which allows you 100K per SharedObject by default for something like a  Flex cookie. When the limit is reached user will be prompted if they want to allow more SharedObject storage:

             

            http://livedocs.adobe.com/flex/3/html/help.html?content=lsos_5.html

             

             

             

            AIR apps do not have this restriction. You can write to the hard drive.

             

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

            1 person found this helpful
            • 3. Re: Allowing a user to save changes
              jimmyoneshot Level 1

              That may work but I'm not sure on how to apply it to my own application. Here's a little bit of my code to show you what I mean. The button marked "populate" populates the left hand tilelist when clicked and also acts as a reset button if the user wants to reset the links back to normal. What I want is when the button marked "save" is clicked for all the changes a user has made to both tilelists to be saved. How can the following code be edited to allow that:-

               

               

               

               

               

               

               

               

               

               

               

               

               

               

               

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

              <mx:WindowedApplication

               

               

              xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

              >

               

               

               

              <mx:Script>

              <![CDATA[

               

               

               

              import

              mx.collections.*;

               

               

               

              private function profile1NewsAndSportReset():void

              {

              profile1NewsAndSportAddLinksTilelist.dataProvider =

               

              new

              ArrayCollection([

              {link:

               

              "www.bbcnews.com", label:"BBC News", icon:"image7", largeImage:"assets/images/bbcnews_small.png", title:"BBC News", description:"BBC News description will go here"

              },

              {link:

               

              "www.itv.com/", label:"ITV", icon:"image5", largeImage:"assets/images/itv_small.png", title:"ITV", description:"ITV Description will go here"

              },

              {link:

               

              "www.skynews.com", label:"Sky News", icon:"image10", largeImage:"assets/images/skynews_small.png", title:"Sky News", description:"Sky News Description will go here"

              },

              ]);

               

              profile1NewsAndSportLinkChoice.dataProvider =

               

              new

              ArrayCollection([]);

              }

               

              ]]>

               

               

              </mx:Script>

               

               

               

              <mx:Button click="profile1NewsAndSportReset()" id="pop" label="populate tilelists" y="0"

              />

               

               

               

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

               

               

               

              <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="419" width="385" top="0" left="128" columnCount="3" rowHeight="145" columnWidth="125" doubleClickEnabled="true" backgroundColor="#000000" borderColor="#FFFFFF" color="#FFFFFF" borderStyle="solid" borderThickness="2" dropShadowEnabled="true"

              />

               

               

               

              <mx:Button click="" id="save" label="Save Changes" x="0" y="30"

              />

               

              </mx:WindowedApplication>

              • 4. Re: Allowing a user to save changes
                Gregory Lafrance Level 6

                Actually saving the state of your app is not easy.

                 

                But I hope I helped.

                • 5. Re: Allowing a user to save changes
                  jimmyoneshot Level 1

                  It seems so unfortunately . I've took on a placement for my University course where the application I'm making will be installed on a system which will allow users to add their favourite links to their own area by dragging and dropping icons which represent these links so saving the tilelist contents is necessary for the app.

                   

                  It's a bit like the deep end to me compared to the last stuff I've done which was just populating an app from an already created xml file.

                  • 6. Re: Allowing a user to save changes
                    jimmyoneshot Level 1

                    I've been doing some research. Could this be done by applying a saveState() function to every item within each tilelist so trhat when they get swapped to another tilelist their state will be saved?

                    • 7. Re: Allowing a user to save changes
                      Gregory Lafrance Level 6

                      To me, all you need is a Save button, and when clicked, it creates a SharedObject (or XML file or whatever if this will be an AIR app).

                       

                      The Save button click event handler will go through the drag target data provider, and if you structure your data to have a "name" field, just write out the names to the SharedObject. On app startup, read in the SharedObject and populate the drag target dataprovider from the drag initiator dataprovider in a for each loop, checking the name field and adding if it is in the ShardObject.

                       

                      Something similar for the user name entered as well.

                       

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

                      1 person found this helpful
                      • 8. Re: Allowing a user to save changes
                        jimmyoneshot Level 1

                        Thanks. You're very helpful. That all makes sense but my only problem is that I struggle to implement such things because I'm a very inexperienced coder.

                         

                        Would it matter that the tilelists are currently populated via array collections created within the application itself or will I have to switch it so they are populated by xml files to begin with i.e. swap all the previous array collection data from the previous code I posted here into xml files or wouldn't that matter?

                        • 9. Re: Allowing a user to save changes
                          jimmyoneshot Level 1

                          Also heres a link to the app as it is so far to give you a rough idea of what I want the finished product to look like. After you click the add new user label in the top left hand corner the first profile appears:-

                           

                          http://10169603.computing.student.edgehill.ac.uk/Coolvision.html

                          • 10. Re: Allowing a user to save changes
                            Gregory Lafrance Level 6

                            I think the first TileList (drag initiator) can be populated with an ArrayCollection in the app, but unless the user has saved, the second TileList dataprovider should be empty, correct? Just initialize that AC, and then populate it from a SharedObject is a save was done.

                             

                            Greg

                            • 11. Re: Allowing a user to save changes
                              jimmyoneshot Level 1

                              Yes that's right. Well actually both tilelists are unpopulated to begin with but clicking the add profile button populates the "Add Links" tilelist from the array collection and then the user can drag these to the tilelist in their area so it's more or less as you said yes.

                               

                              I think I know what you mean and I'm sure you're right. Thanks a lor for helping me out Greg. You're a saint. I'll give it a try if I can figure it out.

                              • 12. Re: Allowing a user to save changes
                                Vanden_B Level 1

                                Simple example to set up the Shared object and get the Shared Object data to an ArrayCollection:

                                 

                                var so:SharedObject = SharedObject.getLocal("mySOdata");
                                so.data.urls = ["url1","url2","url3"];  
                                var flushResult:Object = so.flush();

                                 

                                 

                                 

                                var so:SharedObject = SharedObject.getLocal("mySOdata");   
                                var urls:String = so.data.urls;
                                var urlArr:Array = urls.split(',');

                                var urlAC:ArrayCollection = urlArr;

                                 

                                 

                                Hope this will help you!

                                 

                                 

                                 

                                 

                                • 13. Re: Allowing a user to save changes
                                  Gregory Lafrance Level 6

                                  Just post if you need more help.