Beautiful - this was the key.
The solution is to assign the given arraycollection to a private var, then add
an event listener for CollectionChangeEvent. Changes to the bound collection
are detected properly now.
Thank you Alex and Tim for your help.
private var _myAc:ArrayCollection=new ArrayCollection();
public function set dataInput(data:ArrayCollection):void
{
_myAc=data;
_myAc.addEventListener(CollectionEvent.COLLECTION_CHANGE,datachange);
}
internal function datachange(event:CollectionEvent):void
{
Alert.show('Change detected!');
}
--- In [email protected], Alex Harui <aha...@...> wrote:
>
> I didn't run it, but I would not expect the dataProvider setter to fire when
> you call addItem. I would expect the DataGrid to update as it is listening
> for CollectionChangeEvent from the ArrayCollection. You might need to do the
> same in your component
>
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui
>
> From: [email protected] [mailto:[email protected]] On
> Behalf Of biosmonkey
> Sent: Tuesday, May 05, 2009 2:03 PM
> To: [email protected]
> Subject: [flexcoders] Re: MXML Component and binding with a setter
>
>
>
>
>
> I don't know if I can post source, but let me see...
> Here is source for a sample app:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> layout="vertical" xmlns:ns1="*" horizontalAlign="left">
> <mx:Script>
> <![CDATA[
> import mx.collections.ArrayCollection;
> [Bindable] public var myAC:ArrayCollection=new
> ArrayCollection();
> [Bindable] public var myInt:int=0;
> ]]>
> </mx:Script>
> <mx:DataGrid dataProvider="{myAC}">
> <mx:columns>
> <mx:DataGridColumn headerText="Data" dataField="data"/>
> </mx:columns>
> </mx:DataGrid>
> <ns1:MyComp dataInput="{myAC}" dataIntInput="{myInt}" />
> <mx:Button label="Add Item" click="{myAC.addItem({data:123})}"/>
> <mx:Button label="Increment Int" click="{myInt++}"/>
> </mx:Application>
>
> and here is source for the component "MyComp.mxml":
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
> <mx:Script>
> <![CDATA[
> import mx.collections.ArrayCollection;
> import mx.controls.Alert;
> public function set dataInput(data:ArrayCollection):void
> {
> Alert.show("Setting dataInput="+data);
> }
> public function set dataIntInput(data:int):void
> {
> Alert.show("Setting int="+data);
> }
> ]]>
> </mx:Script>
> </mx:HBox>
>
> All I am doing here is showing a datagrid that is bound to an
> arraycollection, along with a custom component with a setter function
> that is also bound to the same a.c.
>
> If you click the button to add an item, it shows in the datagrid, which
> means it is detecting the change to the arraycollection as I would
> expect. However, the setter in the custom comp does not fire.
>
> As a test, I also added a simple int, which IS being detected by a
> different setter.
>
> --- In [email protected]<mailto:flexcoders%40yahoogroups.com>, "Tim
> Hoff" <TimHoff@> wrote:
> >
> >
> > Probably going to have to show us your getter/setter code; as well as
> > the corresponding private var. If it's an ArrayCollection, it should
> > work.
> >
> > -TH
> >
> >
>