2 Replies Latest reply on Nov 19, 2011 11:25 AM by ArrowUpRight

    Filter Function bug or something else?

    cctman1 Level 1

      Well... I have to admit this one has been baffeling me for hours.

       

      I have the following code which trys to dynamically generate a filter function "filterFunc2" on an ArrayCollection from within a private listener. The below code builds the data set just fine but throws an index out of range error everytime. If I comment out the following lines trying to find the problem:

      //tempColl.filterFunction = filterFunc2;

      // tempColl.refresh();

       

      ..The function executes just fine and all my data shows on screen. Just without the appropriate filter function.

      The crazy thing is though, when I'm debugging my code. If I step through the code that builds the array collection it immidiately then jumps all the way down inside my filter function even though it hasn't even gotten assigned yet.

       

      It basically jumps from the last j++ counter and skips over my if condition logic and jumps right inside the filter function filterFunc2 and attempts to apply the filter. The problem is that I haven't told it which filter to apply yet.

       

      I have no idea whats going on. It acts as if it is binding the filter at compile time regardless of when I try to apply it through my code.

       

      Any Ideas???

       

       

       

        var xml:XML = new XML(evt.obj.data);

                                              var tempColl:ArrayCollection = new ArrayCollection();

                                              var j:int = 0;

                                              for each(var ob:Object in xml.string)

                                              {

                                                        var t1:String = xml.key[j];

                                                        var d1:String = xml.string[j];

       

                                                        var obj:Object = new Object();

                                                        obj.title = t1;

                                                        obj.data = d1;

       

                                                        tempColl.addItem(obj);

                                                        j++;

                                              }

                                              //call the appopriate filter type

                                              if(_sm.dataMode == SettingsModel.FRMode)

                                              {

       

                                              }

                                              else if(_sm.dataMode == SettingsModel.OCMode)

                                              {

                                                        tempColl.filterFunction = filterFunc2;

                                                        tempColl.refresh();

                                              }

                                              else if(_sm.dataMode == SettingsModel.PDMode)

                                              {

                                                        tempColl.filterFunction = filterFunc1;

                                                        tempColl.refresh();

                                              }

       

                          ....

                }

       

      private function filterFunc2(value:Object):Boolean

                                    {

                                              /* if (!value.data)

                                                        return false; */

                       

                                              return (String(value.title).substring(value.title.length-2,value.title.length-1) == "c");

                                    }