The code below (from your example) looks strange.

var validatorFn:Function = Filters.getFilter(options[i]);
validators[validatorFn] = validatorFn;

If validatorFn is a Function, you need a Dictionary to make it work.
Otherwise the toString() value of validatorFn is used on the left hand
side, which is something like [Function] for every function.

Cheers
Ralf.


On Mon, Apr 21, 2008 at 11:10 PM, ivo <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
> Hello all,
>
>  I'd like to understand why if I create a filterFunction for a collection
> out of an array of Functions the filtering fails, but if I use an Object to
> hold them then everything is ok.
>
>  ex:
>
>  /*
>  below would fail with "TypeError: Error#1006: value is not a function" as
> soon as the for loop in the filter function is hit
>  */
>  var validators:Array = [];
>  var options:IList = //...contains property => values
>  for(var i:int=0; i<options.length();i++){
>  var validatorFn:Function = Filters.getFilter(options[i]);
>  validators.push(validatorFn);
>  }
>
>  var filter:Function = function(item:Object):Boolean{
>  var total:int = validators.length();
>  for(var j:int=0; j<total; j++){
>  var fn:Function = validators[j];
>  if(! fn(item)){
>  return false;
>  }
>  }
>  return true;
>  }
>
>  var set:ArrayCollection = new ArrayCollection(/* bunch of items*/);
>  set.filterFunction = filter;
>
>  /*
>  below works
>  */
>  var validators:Object = {};
>  var options:IList = //...contains property => values
>  for(var i:int=0; i<options.length();i++){
>  var validatorFn:Function = Filters.getFilter(options[i]);
>  validators[validatorFn] = validatorFn;
>  }
>
>  var filter:Function = function(item:Object):Boolean{
>  for(var key:String in validators){
>  var fn:Function = validators[key] as Function;
>  if(! fn(item)){
>  return false;
>  }
>  }
>  return true;
>  }
>
>  var set:ArrayCollection = new ArrayCollection([/* bunch of items*/]);
>  set.filterFunction = filter;
>
>  (hope theres no typos, I am writing it as I remember)
>  - Ivo
>
>  



-- 
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany

Reply via email to