I think IMXMLObject must not be required anymore (maybe it was never
required).  It just provides an interface where the object can learn
about the document it belongs to and its id in the document.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Josh McDonald
Sent: Wednesday, August 13, 2008 6:44 PM
To: [email protected]
Subject: Re: [flexcoders] Observing collections

 

And you should probably implement IMXMLObject as well. How does Observe
work without it?

On Thu, Aug 14, 2008 at 11:42 AM, Josh McDonald <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:

Cummon, that's like 15 lines of code, ya bum :)

this is written in gmail, not builder. YMMV. And change it to use weak
referenced listeners, too.

public class ObserveCollection
{
  private var watching:ICollectionView;
  public var handler:Function;

  public function set source(value:ICollectionView) : void
  {
    if (watching)
        watching.removeEventListener(CollectionEvent.CHANGE, changed);
    watching = value;
    watching.addEventListener(CollectionEvent.CHANGE, changed);
    changed();
  }

  private function changed(ignored:*) : void
  {
    if (handler != null)
      handler();


  }
}

On Thu, Aug 14, 2008 at 11:05 AM, Richard Rodseth <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:

A little more context. I'm working on a view that builds itself
dynamically (adding children to various containers) based on a
description.

So suppose my view has a property called "description" which has a
property "things" that is the collection or array.

It's no great hardship to add a listener in the setter for description,
but I wish I could say something like:

<mx:WatchCollection source="{description.things}"
handler="thingsChanged"/>





On Wed, Aug 13, 2008 at 5:51 PM, Alex Harui <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:

There must be some nuance I don't get.  What about:

 

<mx:ArrayCollection collectionChange="myFunction" />

 

________________________________

From: [email protected] <mailto:[email protected]>
[mailto:[email protected] <mailto:[email protected]> ]
On Behalf Of Richard Rodseth
Sent: Wednesday, August 13, 2008 5:28 PM
To: [email protected] <mailto:[email protected]> 
Subject: Re: [flexcoders] Observing collections

 

Hi Alex,

Observe is designed to be used in MXML (it's even billed as the "world's
smallest tag") and that's how I use it.

http://weblogs.macromedia.com/paulw/archives/2006/05/the_worlds_smal.htm
l
<http://weblogs.macromedia.com/paulw/archives/2006/05/the_worlds_smal.ht
ml> 

As it happens it doesn't implement IMXMLObject.

In any case,  since it uses regular binding expressions for the "source"
property, I believe it has the limitation-by-design I referred to. 

On Wed, Aug 13, 2008 at 5:17 PM, Alex Harui <[EMAIL PROTECTED]
<mailto:[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: [email protected] <mailto:[email protected]>
[mailto:[email protected] <mailto:[email protected]> ]
On Behalf Of Richard Rodseth
Sent: Wednesday, August 13, 2008 4:16 PM
To: [email protected] <mailto:[email protected]> 
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?

 

 





-- 
"Therefore, send not to know For whom the bell tolls. It tolls for
thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 




-- 
"Therefore, send not to know For whom the bell tolls. It tolls for
thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 

 

Reply via email to