try this:

package com.adobe.ac
{
        import mx.events.CollectionEvent;
        import mx.collections.ArrayCollection;
        import flash.events.Event;
        import mx.core.Application;
        import mx.core.UIComponent;
        
        
        /**
         * 
         * monitors Collections and react on reassining of the variable 
         * and changes in the collection which are bindable
         * 
         */     
        public class ObserveCollection extends Observer
        {
                private var _handler : Function;
                private var _source : Object;
                
                override public function get handler() : Function
                {
                        return _handler;
                }
        
                public function set handler( value : Function ) : void
                {
                        _handler = value;
                        if( value != null )
                        {
                                isHandlerInitialized = true;
                                if( isHandlerInitialized && isSourceInitialized 
)
                                {
                                        callHandler();
                                }
                        }
                }
  
                override public function get source() : Object
                {
                        return _source;
                }
        
                public function set source( value : Object ) : void
                {       
                        if (_source != null){
                        
_source.removeEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler);

                        }
                        _source = value;
                
_source.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler);

                        isSourceInitialized = true;  
                                
                        if( isHandlerInitialized && isSourceInitialized )
                        {
                                callHandler();
                        }
                }
                
                protected override function callHandler() : void
                {
                        try
                        {
                                handler.call( null, source );
                        }
                        catch( e : Error )
                        {
                                delay( e );
                        }
                }
   
                protected override function delay( e : Error ) : void
                {
                        UIComponent( Application.application ).callLater( 
throwException, [
e ] );
                }
   
                private function throwException( e : Error ) : void
                {
                        throw e;
                }               
                
                private function collectionChangeHandler (event:Event) : void 
                {
                        
                        callHandler();
                }       
                

        }
}


cheers,
Dennis


--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Never used Observe, but if it implements IMXMLObject or you subclass and
> do so, then you can use it in MXML
> 
>  
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of Richard Rodseth
> Sent: Wednesday, August 13, 2008 4:16 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Observing collections
> 
>  
> 
> For some reason I have an aversion to adding event listeners in
> ActionScript, favouring binding expressions and the Observe tag from
> Adobe Consulting. Not sure how rational this is, but there you have it.
> Binding is just so damn elegant.
> 
> However, collections are a problem. It seems that so often you want to
> update something if either the collection itself or its contents
> changes, and you don't really care about the details of the change.
> 
> I suppose if you're a DataGrid watching its dataprovider you do care and
> can minimize updates, but in many of the use cases I've encountered,
> that's not the case - my observer is going to do something with the
> whole collection (or maybe I've just been lazy about exploiting possible
> optimizations).
> 
> Is there anything like the Observe tag that can be instantiated in MXML
> and can trigger a function call on a COLLECTION_CHANGE event?
>


Reply via email to