Hi, I find sometimes just subclassing ArrayCollection works. This way your are defining certain types of collections that do different things.
You can then add functionality to the class with methods or whatever. This works well for me. Then I define the different filter functions based on that collection' current state in the class. Using an interface in the collection then decouples the collection form any implementations. This is one simple class I use to filter included as3 files in a file collection. The source is from a collection defined in the model which is bound to a list with check boxes. package com.teotiGraphix.documentfx.model { import com.teotiGraphix.documentfx.files.IAS3File; import mx.collections.ArrayCollection; public class SourceFileQueue extends ArrayCollection { public static const FILE_INCLUSION_STATE:String = "fileInclusionState"; protected var stateChanged:Boolean = false; //-------------------------------------------------------------------------- // // Public Get-Set :: Properties // //-------------------------------------------------------------------------- //---------------------------------- // state //---------------------------------- private var _state:String; /** * Set the collection state. */ public function get state():String { return _state; } /** * @private */ public function set state(value:String):void { _state = value; stateChanged = true; refresh(); } //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. */ public function SourceFileQueue(source:Array=null) { super(source); state = FILE_INCLUSION_STATE; } /** * @private */ override public function refresh():Boolean { if (stateChanged) { if (_state == FILE_INCLUSION_STATE) { filterFunction = isFileIncluded; } stateChanged = false; } return super.refresh(); } /** * @private */ private function isFileIncluded(item:Object):Boolean { var file:IAS3File; if (item is IAS3File) { file = IAS3File(item); if (file.included) // todo { return true; } } return false; } } } Peace, Mike On 5/24/07, Ralf Bokelberg <[EMAIL PROTECTED]> wrote:
I simply assign the input values to some properties of the filter whenever they change. Cheers, Ralf. On 5/24/07, Kevin < [EMAIL PROTECTED]> wrote: > > using this approach the filter functions still need to reference the > view to get optional filter parameters correct. For example, if you want to > filter based on a user inputed text field you can just do this: > > collection.filterFunction = filter.filterFuncti on (textFld.text); > > > since the filter functions can not accept parameters. > > In thinking about this I am wondering if this would work instead: > > FilterClass.filterByName(collection, textFld.text); > > Then within the class, the static method "filterByName" will > handle assigning a filter function to the collection and using the " > textFld.text" to filter. > > Is there something that I am missing with this approach. > > - Kevin > > > On May 24, 2007, at 2:02 PM, Ralf Bokelberg wrote: > > I'm using a FilterClass, which holds just the filterFunction and some > optional ways to configure the filtering. > Every collection, which needs filtering, gets an instance of this > FilterClass by assigning collection.filterFu nction = > filter.filterFunction; > > Cheers, > Ralf. > > > On 5/24/07, Kevin < [EMAIL PROTECTED] > wrote: > > > > I would like to attempt to separate my filter functions from my view > > so that I am not duplicating code when two views share similar filter > > functions. My idea was to create a class that contains a > > ListCollection and all the appropriate FilterFunctions for that > > collection. The FilterFunctions would then be applied by methods in > > that class. > > > > The problem I am having is that I can't pass any parameters to the > > FilterFunction when I assign it to the specific ListCollection. The > > FilterFunction seems like it needs to be tightly coupled with the > > view in order to work. > > > > To work around this, for application wide filters, I am saving a > > filter value on my model and then referencing the model from my > > FilterFunction (which still isn't ideal). However in some cases this > > isn't appropriate since the filter value doesn't really need to be > > persisted over the entire application. > > > > Does anyone have any thoughts on how to accomplish this? > > > > Thanks for the help, > > > > Kevin > > > > > > -- > Ralf Bokelberg <ralf.bokelberg@ <[EMAIL PROTECTED]>gmail.com > > Flex & Flash Consultant based in Cologne/Germany > Phone +49 (0) 221 530 15 35 > > > -- Ralf Bokelberg <[EMAIL PROTECTED]> Flex & Flash Consultant based in Cologne/Germany Phone +49 (0) 221 530 15 35
-- Teoti Graphix http://www.teotigraphix.com Blog - Flex2Components http://www.flex2components.com You can find more by solving the problem then by 'asking the question'.