2 Replies Latest reply on Mar 2, 2010 2:41 AM by jimmyoneshot

    Struggling With Filtering ArrayCollections/Tilelists

    jimmyoneshot Level 1

      I've done some research on this and I think I'm getting there but I can't seem to get it working in my own app. I have two tilelists categoriesTilelist and productsTilelist populated by two array collections categoriesAC and productsAC which are populated from remote xml files.

       

      One of the attributes in both xml files/array collections is categoryid. What I want is when a user clicks an item in the categories tilelist for only the items within the products tilelist which have the same categoryid value of that particular item to be displayed.

       

      I know I need to use a filter function for this but it doesnt seem to work. I've made a filter function called filterFun and then made a function which should set this filter which I've applied as the item click property of the categoriesTilelist. Here's the code I've got for these:-

       

      if(product.category id == categoriesTilelist. selectedItem. category. categoryid) {


      return true;
      }
      else{
      return false;
      }
      }

       

      public function setFilterFun( ):void{
      productsAC.filterFu nction = filterFun;
      }

       

      That doesn't seem to do anything when I click the categories after I run the app. Can any of you guys tell me where I'm going wrong?
        • 1. Re: Struggling With Filtering ArrayCollections/Tilelists
          cheftimo Level 2

          Hello, jimmy:

           

          I am by no means an expert at this, and don't know enough about your project, but let me mention a couple of things that might help:

           

          First look at this, http://www.timos.com/timos/green/ct/CounterThink.cfm. This thing is working thanks to help I got in these forums a while back and which I still don't completely understand.

           

          The situation here is the same as yours, a TileList that gets filtered by category in another list – in my case, that ComboBox you see on the upper right would be the equivalent of your categoriesTileList; it contains the strings by which the thumbnails TileList gets filtered.

           

          One thing you must MAKE SURE TO DO is 'productAC.refresh()' after you apply the filterfunction.

           

          Play with this and see if you get any results. If not, I will be glad to show you the pertinent code, which you may want to delve into if you are a true masochist.

           

          If you can, it may be a good idea for you to post the project so people in this forum can see it, with ViewSource enabled.

           

          I hope some of this helps. Don't hesitate to ask more questions, as it will benefit both of us.

           

          Best regards,

           

          Carlos

          • 2. Re: Struggling With Filtering ArrayCollections/Tilelists
            jimmyoneshot Level 1

            Thanks a lot for your help Carlos. Your app looks great.

             

            I already discovered yesterday that the productAC.refresh() was missing and added that in but still couldn't seem to get it to work. The problem was in the brackets next to the filterFun function where I was entering product as an object rather than category

             

            I've changed the code to this now and it works great:-

             

             

             

            private function filterFun(category:Object):Boolean {

             

             

            if(category.categoryid == categoriesTilelist.selectedItem.categoryid) {

             

            return true;

            }

             

            else{

             

            return false;

            }

            }

             

             

            public function setFilterFun():void{

            productsAC.filterFunction = filterFun;

            productsAC.refresh();

            }

             

            Thanks for being so helpful mate.