Flex Binding Chains

June 20, 2008

I recently had an issue where I could not get binding in one of my custom components to work. I was simply testing some things out and has a label tag bound to the length property on one of my data model objects. The problem was that the text was not being updated.

< mx:Label text='{obj.anotherObject.yetAnotherObject.length}' />

I initially thought that it might be due to the fact that this object was inherited and the bindable stuff was in the parent class, but it didn’t change when I moved the stuff into the class itself. Next up, blame it on the fact that it was a custom binding job with a read only property:

[Bindable("lengthChanged")]
public function get length():int
{
     return _length;
}

private function addObject(obj:Object, id:String):void
{
     _objects[id] = obj;
     _length++;
     dispatchEvent(new Event("lengthChanged"));
}

(Or something like that, the code has since changed).

This too turned out to be not the case. I changed the property to be a simple public variable on a [Bindable] class. No joy.

I finally figured out that I had to cast the second to last value in the property chain to its proper type. This allowed the compiler to pick up the proper events and add the proper event listeners (or whatever other data binding voodoo that it does).

< mx:Label text='{YetAnotherObjectType(obj.anotherObject.yetAnotherObject).length}' />

Works like a charm.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.