2 Replies Latest reply on Apr 10, 2009 7:26 AM by sanooktuktuk

    filterfunction, tilelist, XMLListCollection

    sanooktuktuk

      I'm just trying to apply a filterfunction to a tilelist with an xmllistcollection as it's dataprovider. Not sure of the syntax to use here.

       

      This is the filter function (it's ok i guess):

       

       

      private function filterFunc(item:Object):Boolean {
                      return item.text().match(new RegExp("^" + stateName.text, "i"));
                  }
      
      This is the XMLListColletion (where the problem is?):
      
      <mx:XMLListCollection id="xmlListColl" source="{xml.image.(@title)}" filterFunction="filterFunc" />
      
      
      This is a sample of the xml file:
      
      
      <gallery>
           <image title="Flex"
                thumbnailImage="assets/fx_appicon-tn.gif"
                fullImage="assets/fx_appicon.jpg" 
                tipText="Flex Thumb"/>
           <image title="Flash n lots of stuff"
                thumbnailImage="assets/fl_appicon-tn.gif"
                fullImage="assets/fl_appicon.jpg" 
                tipText="Flash Thumb"/>
      </gallery>
      
      Seems like it's close to being correct (although I could be totally mistaken!) but it's just not working correctly. Can either get it to immediately filter down to a specific thumbnail image or it get an error "value is not a function" when I type anything in the search box.
      
        • 1. Re: filterfunction, tilelist, XMLListCollection
          shawnyale Level 1

          There is no text() method for an object. If I read this correctly, you are trying to filter your data source on a search term from a search box.  so what you need then is to create your return statement to include the text from the search text input, not the item.  The item parameter in the method signature is going to be the item from your data collection.  I see you have return item.text().match...  An item of type object doesn't have a method called text.  That's where your search error is coming from.  What you need insteead is somthing like this:

           

          <mx:TextInput id="txtSearch"/>

           

          private function filterFunc(item:Object):Boolean {
                          return item.property == txtSearch.text;
                      }

          the property is going to be whatever property in your object that you have your state value in.
          • 2. Re: filterfunction, tilelist, XMLListCollection
            sanooktuktuk Level 1

            How could I tie this into the RegExp?