2 Replies Latest reply on Jul 30, 2009 3:28 AM by jimmyoneshot

    Strange error in sharedObject driven tilelist based application

    jimmyoneshot Level 1

      I’ve recently made an application (with some great help from this forum) that allows users to drag items between tilelists and then save the changes to the tilelists via the sharedObject method simply by clicking the save button so that next time they open the app any changes will still be there however I now have a strange error message that seems to appear.

      What happens is if the user drags ALL of the items from the left hand tilelist into the right hand tilelist and saves their changes and then closes and reopens the app the left tilelist then contains no items and the right tilelist contains all of the items which is all right so far HOWEVER if the user now clicks the save button without interacting with the tilelists an error pops up something along the lines of “Error #1009: Cannot access a property or method of a null object reference”. It seems harmless but when I finalise the app I don’t want users to add all the items to the right tilelist save there changes, close and reopen and then get an error if they happen to click on save again.

      I can’t figure out where it’s coming from but here’s the code for the app:-

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

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

       

        <mx:Script>

          <![CDATA[

            import mx.collections.*;

            import flash.net.SharedObject;

            public var profile1NewsAndSportSO:SharedObject;

            private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = 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"}

            ]);

           

            private var profile1NewsAndSportaddLinksAC: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{

              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(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: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="129"

          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="129"

          width="385" top="5" left="128" columnCount="3" rowHeight="145" columnWidth="125"

          backgroundColor="#000000" color="#FFFFFF"/>

        <mx:Button click="saveprofile1NewsAndSport(event)" id="save" label="Save Changes"

          x="5" y="38" width="113" height="25.5"/>

       

         

      </mx:Application>

       

        • 1. Re: Strange error in sharedObject driven tilelist based application
          Gregory Lafrance Level 6

          This should fix it.

           

          If this post answers your question or helps, 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="initprofile1NewsAndSportSO();">
            <mx:Script>
              <![CDATA[
                import mx.collections.*;
                import flash.net.SharedObject;
                public var profile1NewsAndSportSO:SharedObject;
                private var profile1NewsAndSportaddLinksFullAC:ArrayCollection = 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"}
                ]);
                
                private var profile1NewsAndSportaddLinksAC: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{
                  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: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="129" 
              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="129" 
              width="385" top="5" left="128" columnCount="3" rowHeight="145" columnWidth="125" 
              backgroundColor="#000000" color="#FFFFFF"/>
            <mx:Button click="saveprofile1NewsAndSport(event)" id="save" label="Save Changes" 
              x="5" y="38" width="113" height="25.5"/>
              
          </mx:Application>