15 Replies Latest reply on Aug 11, 2009 11:56 AM by jimmyoneshot

    Exchanging items between tilelists upon button click

    jimmyoneshot Level 1

      I have an app that allows users to exchange items between two tilelists and then save the changes they've made or reset any changes.

       

      What I want now however is for the users to be able to click the "Add selected link" and "Remove selected link" buttons and whatever item they have currently selected in that tilelist will be moved to the other tilelist. For example if a user clicks on an item in the left hand tilelist and then clicks the "Add selected link" button whilst the item is still selected that item will then be switched into the right hand tilelist. I'm not sure if this is possible without dragging each item though.

       

      Basically I want to advance the app so it contains this functionality aswell as drag and drop. The reason for all this is that my app will be installed on a system and some versions of this system will be operated by a tv like remote control so obviously dragging and dropping would be tricky without a mouse so this is just to offer an alternative.

       

       

      <?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:Button x="269" y="142" label="Add Selected Link" id="profile1NewsAndSportAddLinkButton"

      />

       

       

      <mx:Button x="774" y="142" label="Remove Selected Link" id="profile1NewsAndSportRemoveLinkButton"

      />

       

      </mx:Application>

        • 1. Re: Exchanging items between tilelists upon button click
          Gregory Lafrance Level 6

          Just do this:

           

          private function myAddButtonClickHandler():void{

              for each(var a:uint in list1.selectedindices){

                  if(!ArrayCollection(list2.dataProvider).contains(ArrayCollection(list1.dataProvider).getI temAt(a))){

                      ArrayCollection(list2.dataProvider).addItem(ArrayCollection(list1.dataProvider).getItemAt (a));

                  }

              }

          }

           

          similar for remove.

           

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

          1 person found this helpful
          • 2. Re: Exchanging items between tilelists upon button click
            jimmyoneshot Level 1

            Ok I've added in the names of my 2 tilelists into the script (in place of list 1 and list 2) and added the add button click function to the click of the add button however now whenever I run it and select an item in the tilelist and click the add button I get the error "#1009: Cannot access a property or method of a null object reference" pointing to the line -

             

            if(!ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).contains(ArrayCollection(pr ofile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a))){

             

            I've noticed however if I drag the items around a bit and THEN click the add button with an item selected in the left hand tilelist it works but it creates a copy of the item rather than moving the item itself. It just seems it doesn't work when the app is in it's default state for some reason.

             

            Is it possible to set it so that clicking the add button will move the whole item from tilelist to tilelist rather than creating a copy and setting it so that it'll work as soon as the interface starts i.e with all items in their default positions?

             

            Sorry I'm clueless

             

            Here it is now:-

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

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

            <mx:Application

             

             

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

            >

             

             

             

            <mx:Script>

            <![CDATA[

             

             

            private function profile1NewsAndSportAddButtonClickHandler():void

            {

             

             

             

            for each(var a:uint in

            profile1NewsAndSportAddLinksTilelist.selectedIndices){

             

             

             

            if

            (!ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).contains(ArrayCollection(pr ofile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a))){

             

            ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).addItem(ArrayCollection(profi le1NewsAndSportAddLinksTilelist.dataProvider) .getItemAt(a));

             

            }

             

            }

             

            }

             

            ]]>

             

             

            </mx:Script>

             

             

             

            <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="10" left="519" 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="10" left="126" 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:Button x="126" y="147" label="Add" id="profile1NewsAndSportAddSelectedLinkButton" click="profile1NewsAndSportAddButtonClickHandler()"

            />

             

             

            <mx:Button x="519" y="147" label="Remove" id="profile1NewsAndSportRemoveSelectedLinkButton"

            />

             

            </mx:Application>

             

            • 3. Re: Exchanging items between tilelists upon button click
              Gregory Lafrance Level 6

              You posted code is all messed up and when I copy it won't compile. I've fixed it in the past but its getting too big for me to spend the time to fix it, and anyway\ I've been meaning to ask you change how you post it for a while.

               

              When you post your code you need to click the >> to the right of the smily face in the toolbar here, and select Syntax Highlighting - Java.

               

              After that you will need to click in the box that is added and post your code.

               

              I usually copy from Flex Builder, paste to a test editor, then copy from there and paste into the box I mentioned above.

              • 4. Re: Exchanging items between tilelists upon button click
                jimmyoneshot Level 1

                Whoops, so sorry about that, I never realised at all

                 

                That is a very useful addition though as I've noticed code is usually messed up when it gets pasted into here. I've pasted it into notepad and now into the box below as you say. Here it is:-

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initprofile1NewsAndSportSO();">
                  
                  <mx:Script>
                   <![CDATA[
                   private function profile1NewsAndSportAddButtonClickHandler():void{
                    for each(var a:uint in profile1NewsAndSportAddLinksTilelist.selectedIndices){
                        if(!ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).contains(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a))){
                            ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).addItem(ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a));
                        }
                    }
                }
                   ]]>
                  </mx:Script>
                  
                  <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="10" left="519" 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="10" left="126" 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:Button x="126" y="147" label="Add" id="profile1NewsAndSportAddSelectedLinkButton" click="profile1NewsAndSportAddButtonClickHandler()"/>
                  <mx:Button x="519" y="147" label="Remove" id="profile1NewsAndSportRemoveSelectedLinkButton"/>
                    
                </mx:Application>
                
                • 5. Re: Exchanging items between tilelists upon button click
                  Gregory Lafrance Level 6

                  Uncomment the one line currently commented out if you want to removed item added back to the TileList on the left.

                   

                  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[
                     private function profile1NewsAndSportAddButtonClickHandler():void{
                      for each(var a:uint in profile1NewsAndSportAddLinksTilelist.selectedIndices){
                          if(!ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).contains(ArrayCollection (profile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a))){
                              ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).addItem(ArrayCollection(prof ile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a));
                              ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).removeItemAt(a);
                          }
                      }
                    }

                     private function profile1NewsAndSportRemoveButtonClickHandler():void{
                      for each(var a:uint in profile1NewsAndSportLinkChoice.selectedIndices){
                        ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).addItem(ArrayCollectio n(profile1NewsAndSportLinkChoice.dataProvider).getItemAt(a));
                        //ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).removeItemAt(a);
                      }
                    }
                     ]]>
                    </mx:Script>
                   
                    <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="10" left="519" columnCount="5" rowHeight="145"
                      columnWidth="125" backgroundColor="#000000" color="#FFFFFF"
                      creationComplete="profile1NewsAndSportLinkChoice.selectedIndex=0"/>
                    <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold"
                      dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="129"
                      width="385" top="10" left="126" columnCount="3" rowHeight="145" columnWidth="125"
                      backgroundColor="#000000" color="#FFFFFF"
                      creationComplete="profile1NewsAndSportAddLinksTilelist.selectedIndex=0"/>
                    <mx:Button click="saveprofile1NewsAndSport(event)" id="save" label="Save Changes"
                      x="5" y="38" width="113" height="25.5"/>
                    <mx:Button x="126" y="147" label="Add" id="profile1NewsAndSportAddSelectedLinkButton" click="profile1NewsAndSportAddButtonClickHandler()"/>
                    <mx:Button x="519" y="147" label="Remove" id="profile1NewsAndSportRemoveSelectedLinkButton" click="profile1NewsAndSportRemoveButtonClickHandler()"/>
                     
                  </mx:Application>

                  1 person found this helpful
                  • 6. Re: Exchanging items between tilelists upon button click
                    jimmyoneshot Level 1

                    It's strange. That works fine as long as I've either clicked the reset button first or moved an item from 1 tilelist to the other however if the app is in it's default state when it first starts up and all items are in the left hand tilelist and I click one and click the add button I get the "Error #1009: Cannot access a property or method of a null object reference" error.

                     

                    Here's what I mean by in its default state when the error occurs:-

                     

                    http://i223.photobucket.com/albums/dd147/jimmyoneshot/def.jpg

                     

                    Sorry about this.

                    • 7. Re: Exchanging items between tilelists upon button click
                      Gregory Lafrance Level 6

                      Did you see I am doing this:

                       

                      creationComplete="profile1NewsAndSportAddLinksTilelist.selectedIndex=0"/>
                      creationComplete="profile1NewsAndSportLinkChoice.selectedIndex=0"/>

                      That ensures something is selected at startup.

                       

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

                      • 8. Re: Exchanging items between tilelists upon button click
                        jimmyoneshot Level 1

                        Yep I noticed that. That part works fine and an item is selected as soon as the app runs but what is happening is that as soon as I run the app and click the add button with an item selected in the left hand tilelist I get the "Error #1009: Cannot access a property or method of a null object reference" error.

                         

                        This only happens in the default state like in the above screenshot i.e. all items are in their original positions in the left hand tilelist and the app is started up, an item is selected in the left hand list and the add button is clicked. This causes the error.

                         

                        It's very strange indeed as I can't see nothing wrong with the code and the object is not 'null'

                        • 9. Re: Exchanging items between tilelists upon button click
                          Gregory Lafrance Level 6

                          Have you pasted the code to an AIR app? The code I provided works fine for me.

                          • 10. Re: Exchanging items between tilelists upon button click
                            jimmyoneshot Level 1

                            Not yet. I was just testing it in a Flex app for now. So it runs ok in AIR you think? I'll give it a try.

                            • 11. Re: Exchanging items between tilelists upon button click
                              jimmyoneshot Level 1

                              It works perfect in AIR. So sorry about that my mistake. Well done mate.

                              • 12. Re: Exchanging items between tilelists upon button click
                                Gregory Lafrance Level 6

                                Actually, it worked fine for me in a Flex app as well. But I'm glad it worked for you in AIR at least.

                                • 13. Re: Exchanging items between tilelists upon button click
                                  jimmyoneshot Level 1

                                  It actually seems I'm still getting the error.  It just didn't appear last time for some reason

                                   

                                  It seems that it only happens when either of the tilelists is fully populated and the other is empty. To describe exactly what I mean if I do the following:-

                                   

                                  - Start the application

                                  - Drag all items into the right hand tilelist

                                  - Click 'Save changes'

                                  - Close and reopen / refresh the app

                                  - Click any item in the right hand tilelist / leave the one that is currently selected as the selected item

                                  - Click the remove button

                                   

                                  Doing the above for me using the exact code you sent produces the error "Cannot access a property or method of a null object reference".

                                   

                                  The same happens for the add button if ALL items are in the left hand tilelist when the app starts. It's crazy

                                  • 14. Re: Exchanging items between tilelists upon button click
                                    Gregory Lafrance Level 6

                                    This code should fix the problem. I tried to make it so after adding an item the selected index updates, but I was getting some strange results, so if that is a concern you may need to start a new post.

                                     

                                    <?xml version="1.0" encoding="utf-8"?>
                                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initprofile1NewsAndSportSO();">
                                     
                                      <mx:Script>
                                       <![CDATA[
                                       private function profile1NewsAndSportAddButtonClickHandler():void{
                                        for each(var a:uint in profile1NewsAndSportAddLinksTilelist.selectedIndices){
                                          if(profile1NewsAndSportLinkChoice.dataProvider != null){
                                            if(!ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).contains(ArrayCollection (profile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a))){
                                                ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).addItem(ArrayCollection(prof ile1NewsAndSportAddLinksTilelist.dataProvider).getItemAt(a));
                                                ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).removeItemAt(a);
                                            }
                                          }else{
                                            profile1NewsAndSportLinkChoice.dataProvider.addItem(ArrayCollection(profile1NewsAndSportA ddLinksTilelist.dataProvider).getItemAt(a));
                                            ArrayCollection(profile1NewsAndSportAddLinksTilelist.dataProvider).removeItemAt(a);
                                          }
                                        }
                                      }

                                       private function profile1NewsAndSportRemoveButtonClickHandler():void{
                                        for each(var a:uint in profile1NewsAndSportLinkChoice.selectedIndices){
                                          ArrayCollection(profile1NewsAndSportLinkChoice.dataProvider).removeItemAt(a);
                                        }
                                      }
                                       ]]>
                                      </mx:Script>
                                     
                                      <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{
                                           profile1NewsAndSportLinkChoice.dataProvider = new ArrayCollection();
                                           profile1NewsAndSportAddLinksTilelist.dataProvider = new ArrayCollection();
                                            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="10" left="519" columnCount="5" rowHeight="145"
                                        columnWidth="125" backgroundColor="#000000" color="#FFFFFF"
                                        creationComplete="profile1NewsAndSportLinkChoice.selectedIndex=0"/>
                                      <mx:TileList id="profile1NewsAndSportAddLinksTilelist" fontWeight="bold"
                                        dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" height="129"
                                        width="385" top="10" left="126" columnCount="3" rowHeight="145" columnWidth="125"
                                        backgroundColor="#000000" color="#FFFFFF"
                                        creationComplete="profile1NewsAndSportAddLinksTilelist.selectedIndex=0"/>
                                      <mx:Button click="saveprofile1NewsAndSport(event)" id="save" label="Save Changes"
                                        x="5" y="38" width="113" height="25.5"/>
                                      <mx:Button x="126" y="147" label="Add" id="profile1NewsAndSportAddSelectedLinkButton" click="profile1NewsAndSportAddButtonClickHandler()"/>
                                      <mx:Button x="519" y="147" label="Remove" id="profile1NewsAndSportRemoveSelectedLinkButton" click="profile1NewsAndSportRemoveButtonClickHandler()"/>
                                       
                                    </mx:Application>

                                    • 15. Re: Exchanging items between tilelists upon button click
                                      jimmyoneshot Level 1

                                      That works great now. No errors at all.

                                       

                                      Sorry about that I should have posted a new topic with my last post in because I forgot that I'd already gave you a Correct Answer for this topic

                                       

                                      I acually prefer it without an index initially selected anyway so I've removed the creationComplete from both tilelists. No worries there.

                                       

                                      Thanks a lot