4 Replies Latest reply on Mar 24, 2010 3:50 AM by jimmyoneshot

    Dynamic Shared Object - Is This Possible?

    jimmyoneshot Level 1

      What I want in my app is to have 2 tilelists and an array collection of items which will populate the first tilelist and these objects can be dragged between both tilelists. Then the user can click a save button which will save the statuses of both tilelists so the items that are present/not present in each tilelist when the app is closed will still be there when the app is restarted.

       

      The problem is I want my array collection to be populated dynamically from mysql data on a server.

       

      I have no problem getting dynamic data from a mysql database into an array colllection via http request and I have no problem getting the shared object to work IF the array collection is defined within the app the usual way but I'm having trouble getting these 2 things to work together.

       

      Can anybody tell me if it is indeed possible to have a dynamically populated array collection stored as a shared object on the user's system and would anyone be willing to help me out if I post my code so far? Cheers.
        • 1. Re: Dynamic Shared Object - Is This Possible?
          Karl_Sigiscar_1971 Level 3

          You can serialize an object to the Shared Object using the [RemoteClass] metadata in order to retain its type.

           

          E.g:

           

            
               [Bindable]
               [RemoteClass]
               public class UserPreferences
               {
                   // The current locale
                   public var locale:String = "en_US";

                   // Date separator
                   public var dateSeparator:String = "/";
                  
                   // Skins
                   public var skinVersion:String = "Alternate";
                  
                   // The last selected currency
                   private var _currency:String = "USD";
                  
                   // Property you do not want to be serialized
                  
                   [Transient]
                   private var dummy;
                  

                   // ********************************************************************* /
                   // Getters/Setters
                   // ********************************************************************* /
                  
                   public function get currency():String
                   {
                       return this._currency;
                   }
                  
                   public function set currency(value:String):void
                   {
                       this._currency = value;
                   }
              }
          }

          1 person found this helpful
          • 2. Re: Dynamic Shared Object - Is This Possible?
            jimmyoneshot Level 1

            Cheers for the help but I'm not sure how I can apply that to my code. Previously I defined the array collections in the application and this worked fine but now I'm retrieving them from the last result of a http request and have commented out the old array collections. I'm not sure what I'm doing wrong. Here's what I've got so far:-

             

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:WindowedApplication
            
             xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="newsService.send(); initprofile1NewsAndSportSO()">
            
            <mx:Script>
            <![CDATA[
            
            
            import mx.rpc.events.ResultEvent;
            
            import mx.collections.*;
            
            import flash.net.SharedObject;
            
            
            public var profile1NewsAndSportSO:SharedObject;
            [
            
            Bindable]
            
            private var profile1NewsAndSportaddLinksFullAC:ArrayCollection;
            [
            
            Bindable]
            
            private var profile1NewsAndSportaddLinksAC:ArrayCollection;
            
            
            private function newsResultHandler(event:ResultEvent):void{
            profile1NewsAndSportaddLinksFullAC=newsService.lastResult.newscategory.news 
            as ArrayCollection;profile1NewsAndSportaddLinksAC=newsService.lastResult.newscategory.news 
            
            as ArrayCollection; }
            
            
            // private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = new ArrayCollection([
            // {label:"BBC News"},
            // {label:"ITV"},
            // {label:"Sky News"}
            // ]);
            
            // private var profile1NewsAndSportaddLinksAC:ArrayCollection = new ArrayCollection([
            // {label:"BBC News"},
            // {label:"ITV"},
            // {label:"Sky News"}
            // ]);
            
            
            private function profile1NewsAndSportReset():void{resetprofile1NewsAndSportAC();
            profile1NewsAndSportAddLinksTilelist.dataProvider 
            = profile1NewsAndSportaddLinksAC;
            profile1NewsAndSportLinkChoice.dataProvider = 
            
            new ArrayCollection([]); }
            
            
            
            private function resetprofile1NewsAndSportAC():void{profile1NewsAndSportaddLinksAC.removeAll();
            
            
            for each(var obj:Object in profile1NewsAndSportaddLinksFullAC){profile1NewsAndSportaddLinksAC.addItem(obj);
            }
            }
            
            
            
            private function initprofile1NewsAndSportSO():void{profile1NewsAndSportSO = SharedObject.getLocal(
            
            "profile1NewsAndSport");
            
            if(profile1NewsAndSportSO.size > 0){
            
            if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList){
            
            if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList != "empty"){
            
            var profile1NewsAndSportaddList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportaddList.split(",");
            
            var profile1NewsAndSporttempAC1:ArrayCollection = new ArrayCollection();
            
            for each(var str:String in profile1NewsAndSportaddList){
            
            for each(var obj1:Object in profile1NewsAndSportaddLinksAC){
            
            if(str == obj1.label){profile1NewsAndSporttempAC1.addItem(obj1);
            
            
            continue;}
            }
            }
            
            
            if(profile1NewsAndSporttempAC1.length > 0){profile1NewsAndSportAddLinksTilelist.dataProvider = profile1NewsAndSporttempAC1;
            } 
            }
            }
            
            
            if(profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList){
            
            var profile1NewsAndSportchoiceList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList.split(",");
            
            var profile1NewsAndSporttempAC2:ArrayCollection = new ArrayCollection();
            
            for each(var str2:String in profile1NewsAndSportchoiceList){
            
            for each(var obj2:Object in profile1NewsAndSportaddLinksAC){
            
            if(str2 == obj2.label){profile1NewsAndSporttempAC2.addItem(obj2);
            
            
            continue;}
            }
            }
            
            
            if(profile1NewsAndSporttempAC2.length > 0){profile1NewsAndSportLinkChoice.dataProvider = profile1NewsAndSporttempAC2;
            } 
            }
            }
            
            else{profile1NewsAndSportReset();
            }
            }
            
            
            private function saveprofile1NewsAndSport(event:MouseEvent):void{
            
            var profile1NewsAndSportaddList:String = "";
            
            if(profile1NewsAndSportAddLinksTilelist.dataProvider){
            
            if(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).length > 0){
            
            for each(var obj1:Object in profile1NewsAndSportAddLinksTilelist.dataProvider){
            profile1NewsAndSportaddList += obj1.label + 
            
            ",";}
            }
            
            else{profile1NewsAndSportaddList = 
            
            "empty";}
            }
            profile1NewsAndSportSO.data.profile1NewsAndSportaddList = profile1NewsAndSportaddList; 
            
            
            var profile1NewsAndSportchoiceList:String = "";
            
            for each(var obj2:Object in profile1NewsAndSportLinkChoice.dataProvider){
            profile1NewsAndSportchoiceList += obj2.label + 
            
            ",";}
            profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList = profile1NewsAndSportchoiceList;
            profile1NewsAndSportSO.flush();
            }
            ]]>
            
            
            </mx:Script>
            
            
            <mx:HTTPService id="newsService" resultFormat="object" result="newsResultHandler(event)" url="http://www.coolvisiontest.com/getnews.php"/> 
            
            
            <mx:TileList id="profile1NewsAndSportLinkChoice" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="129" width="650" top="5" left="521" columnCount="5" rowHeight="145" columnWidth="125" backgroundColor="#000000" color="#FFFFFF">
            
            <mx:itemRenderer>
            
            <mx:Component>
            
            <mx:Canvas width="125" height="129" backgroundColor="#000000">
            
            <mx:Image source="{'http://www.coolvisiontest.com/interfaceimages/images/'+ data.icon}" top="5" horizontalCenter="0"/>
            
            <mx:Label text="{data.label}" bottom="1" horizontalCenter="0"/>
            
            </mx:Canvas> 
            
            </mx:Component>
            
            </mx:itemRenderer> 
            
            </mx:TileList>
            
            
            <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="129" width="385" top="5" left="128" columnCount="3" rowHeight="145" columnWidth="125" backgroundColor="#000000" color="#FFFFFF">
            
            <mx:itemRenderer>
            
            <mx:Component>
            
            <mx:Canvas width="125" height="129" backgroundColor="#000000">
            
            <mx:Image source="{'http://www.coolvisiontest.com/interfaceimages/images/'+ data.icon}" top="5" horizontalCenter="0"/>
            
            <mx:Label text="{data.label}" bottom="1" horizontalCenter="0"/>
            
            </mx:Canvas> 
            
            </mx:Component>
            
            </mx:itemRenderer> 
            
            </mx:TileList>
            
            
            <mx:Button click="profile1NewsAndSportReset()" id="reset" label="Reset" y="5" height="25" x="5"/>
            
            
            <mx:Button click="saveprofile1NewsAndSport(event)" id="save" label="Save Changes" x="5" y="38" width="113" height="25.5"/>
            
            </mx:WindowedApplication>
            
            
            
            
            
            • 3. Re: Dynamic Shared Object - Is This Possible?
              Gregory Lafrance Level 6

              Your code produces errors. You need to fix it before we can help.

              1 person found this helpful
              • 4. Re: Dynamic Shared Object - Is This Possible?
                jimmyoneshot Level 1

                Hi Greg. The way I usually post code is by clicking the small arrows above and then clicking syntax highlighting and then xml. The problem is this seems to remove all of the quotation marks ("") from my code which is what is causing the errors you mentioned. I've posted it below just by simply copying and pasting. I hope that works better. Cheers for your help:-

                 

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

                <mx:WindowedApplication

                 

                 

                xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="newsService.send(); initprofile1NewsAndSportSO()">

                 

                <mx:Script>

                <![CDATA[

                 

                 

                import mx.rpc.events.ResultEvent;

                 

                import mx.collections.*;

                 

                import flash.net.SharedObject;

                 

                 

                public var profile1NewsAndSportSO:SharedObject;

                 

                [

                Bindable]

                 

                private var profile1NewsAndSportaddLinksFullAC:ArrayCollection;

                 

                [

                Bindable]

                 

                private var profile1NewsAndSportaddLinksAC:ArrayCollection;

                 

                 

                private function newsResultHandler(event:ResultEvent):void

                {

                profile1NewsAndSportaddLinksFullAC=newsService.lastResult.newscategory.news

                as ArrayCollection;

                profile1NewsAndSportaddLinksAC=newsService.lastResult.newscategory.news

                as ArrayCollection;

                }

                 

                // private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = new ArrayCollection([

                // {label:"BBC News"},

                // {label:"ITV"},

                // {label:"Sky News"}

                // ]);

                 

                // private var profile1NewsAndSportaddLinksAC:ArrayCollection = new ArrayCollection([

                // {label:"BBC News"},

                // {label:"ITV"},

                // {label:"Sky News"}

                // ]);

                 

                 

                private function profile1NewsAndSportReset():void{

                resetprofile1NewsAndSportAC();

                profile1NewsAndSportAddLinksTilelist.dataProvider = profile1NewsAndSportaddLinksAC;

                profile1NewsAndSportLinkChoice.dataProvider =

                new ArrayCollection([]);

                }

                 

                 

                private function resetprofile1NewsAndSportAC():void{

                profile1NewsAndSportaddLinksAC.removeAll();

                 

                for each(var obj:Object in profile1NewsAndSportaddLinksFullAC){

                profile1NewsAndSportaddLinksAC.addItem(obj);

                }

                }

                 

                 

                private function initprofile1NewsAndSportSO():void{

                profile1NewsAndSportSO = SharedObject.getLocal(

                "profile1NewsAndSport");

                 

                if(profile1NewsAndSportSO.size > 0){

                 

                if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList){

                 

                if(profile1NewsAndSportSO.data.profile1NewsAndSportaddList != "empty"){

                 

                var profile1NewsAndSportaddList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportaddList.split(",");

                 

                var profile1NewsAndSporttempAC1:ArrayCollection = new ArrayCollection();

                 

                for each(var str:String in profile1NewsAndSportaddList){

                 

                for each(var obj1:Object in profile1NewsAndSportaddLinksAC){

                 

                if(str == obj1.label){

                profile1NewsAndSporttempAC1.addItem(obj1);

                 

                continue;

                }

                }

                }

                 

                if(profile1NewsAndSporttempAC1.length > 0){

                profile1NewsAndSportAddLinksTilelist.dataProvider = profile1NewsAndSporttempAC1;

                }

                }

                }

                 

                if(profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList){

                 

                var profile1NewsAndSportchoiceList:Array = profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList.split(",");

                 

                var profile1NewsAndSporttempAC2:ArrayCollection = new ArrayCollection();

                 

                for each(var str2:String in profile1NewsAndSportchoiceList){

                 

                for each(var obj2:Object in profile1NewsAndSportaddLinksAC){

                 

                if(str2 == obj2.label){

                profile1NewsAndSporttempAC2.addItem(obj2);

                 

                continue;

                }

                }

                }

                 

                if(profile1NewsAndSporttempAC2.length > 0){

                profile1NewsAndSportLinkChoice.dataProvider = profile1NewsAndSporttempAC2;

                }

                }

                }

                else{

                profile1NewsAndSportReset();

                }

                }

                 

                private function saveprofile1NewsAndSport(event:MouseEvent):void{

                 

                var profile1NewsAndSportaddList:String = "";

                 

                if(profile1NewsAndSportAddLinksTilelist.dataProvider){

                 

                if(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).length > 0){

                 

                for each(var obj1:Object in

                profile1NewsAndSportAddLinksTilelist.dataProvider){

                profile1NewsAndSportaddList += obj1.label +

                ",";

                }

                }

                else{

                profile1NewsAndSportaddList =

                "empty";

                }

                }

                profile1NewsAndSportSO.data.profile1NewsAndSportaddList = profile1NewsAndSportaddList;

                 

                var profile1NewsAndSportchoiceList:String = "";

                 

                for each(var obj2:Object in

                profile1NewsAndSportLinkChoice.dataProvider){

                profile1NewsAndSportchoiceList += obj2.label +

                ",";

                }

                profile1NewsAndSportSO.data.profile1NewsAndSportchoiceList = profile1NewsAndSportchoiceList;

                profile1NewsAndSportSO.flush();

                }

                ]]>

                 

                </mx:Script>

                 

                 

                <mx:HTTPService id="newsService" resultFormat="object" result="newsResultHandler(event)" url="http://www.coolvisiontest.com/getnews.php"/>

                 

                 

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

                 

                <mx:itemRenderer>

                 

                <mx:Component>

                 

                <mx:Canvas width="125" height="129" backgroundColor="#000000">

                 

                <mx:Image source="{'http://www.coolvisiontest.com/interfaceimages/images/'+ data.icon}" top="5" horizontalCenter="0"/>

                 

                <mx:Label text="{data.label}" bottom="1" horizontalCenter="0"/>

                 

                </mx:Canvas>

                 

                </mx:Component>

                 

                </mx:itemRenderer>

                 

                </mx:TileList>

                 

                 

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

                 

                <mx:itemRenderer>

                 

                <mx:Component>

                 

                <mx:Canvas width="125" height="129" backgroundColor="#000000">

                 

                <mx:Image source="{'http://www.coolvisiontest.com/interfaceimages/images/'+ data.icon}" top="5" horizontalCenter="0"/>

                 

                <mx:Label text="{data.label}" bottom="1" horizontalCenter="0"/>

                 

                </mx:Canvas>

                 

                </mx:Component>

                 

                </mx:itemRenderer>

                 

                </mx:TileList>

                 

                 

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

                 

                 

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

                 

                </mx:WindowedApplication>