In general each object and sub-object and property needs to dispatch events 
when changed, and your binding needs to watch each level.  IOW, for the 
expression a.b.c, there needs to be an event dispatched when a changes, when b 
changes and when c changes, and if you want to detect changes to c, your 
binding expression needs to be checking c for changes.

In this example, there is no events dispatched when xlc changes (which should 
cause a warning), and there is no binding to tc1.xlc so nothing is checking for 
changes to xlc (which is why you didn't get a warning).  It is always easier to 
set this up in MXML than in AS, so you have some choices about how to set it up.

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 Greg Lafrance
Sent: Monday, November 16, 2009 9:38 PM
To: [email protected]
Subject: [flexcoders] Re: Binding not working in custom class and DataGrid 
using XMLListCollection



I'm kind of new to this type of binding. I'm not getting any warnings. I just 
thought the binding would work as is.

--- In [email protected]<mailto:flexcoders%40yahoogroups.com>, Alex 
Harui <aha...@...> wrote:
>
> Are you getting binding warnings in the console? TestClass1 doesn't seem to 
> declare any bindable events or dispatch any.
>
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui
>
> From: [email protected]<mailto:flexcoders%40yahoogroups.com> 
> [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com>] On 
> Behalf Of Greg Lafrance
> Sent: Monday, November 16, 2009 9:15 PM
> To: [email protected]<mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] Binding not working in custom class and DataGrid using 
> XMLListCollection
>
>
>
> I have a class with an XMLListCollection, and I am using that class xlc as 
> the dataProvider in a DataGrid, but when I change the xlc in the class 
> instance, the DataGrid does not reflect the change. Any ideas?
>
> ----- TestClass1.as -----
> package
> {
> import flash.events.EventDispatcher;
>
> import mx.collections.XMLListCollection;
>
> public class TestClass1 extends EventDispatcher{
> private var xml_1:XML =
> <root>
> <item>one</item>
> <item>two</item>
> <item>three</item>
> </root>;
>
> private var xml_2:XML =
> <root>
> <item>ten</item>
> <item>twenty</item>
> <item>thirty</item>
> </root>;
>
> private var _xlc:XMLListCollection = new XMLListCollection(xml_1..item);
>
> public function TestClass1(){
> }
>
> public function get xlc():XMLListCollection{
> return this._xlc;
> }
>
> public function loadData():void{
> this._xlc = new XMLListCollection(xml_2..item);
> }
> }
> }
>
> ----- TestApp.mxml -----
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> width="100%">
> <mx:Script>
> <![CDATA[
> import mx.collections.XMLListCollection;
> private var tc1:TestClass1 = new TestClass1();
>
> [Bindable] private var xlcCollection:XMLListCollection = tc1.xlc;
> ]]>
> </mx:Script>
> <mx:DataGrid dataProvider="{xlcCollection}"/>
> <mx:Button label="Change Data" click="tc1.loadData();"/>
> </mx:Application>
>

Reply via email to