I'm having some troubles with data binding and a named event generated
by a custom non-visual component.  What I'm trying to do is have a
property (say, 'data') which, when it changes, triggers the usual
data-binding updates, but also fires an event that can be listened to
in the MXML.  For example:

<foo:MyClass id="thingy" dataChanged="Alert.show('hi mom');"/>
<mx:Label text={thingy.data}"/>

I can't seem to meet both of these requirements without throwing two
separate events.  Is this what I should expect?

When I do this:

[Event(name="dataChanged")]
public class MyClass {

[Bindable(name="dataChanged")]
public function set data(data:Object):void {
  this._data = data;
  dispatchEvent( new Event("dataChanged") );

..then the data binding doesn't work.  (The label text doesn't get
updated.)  It seems I have to resort to vanilla data binding (with no
event name), and in addition throw a 'dataChanged' event of my own.

[Event(name="dataChanged")]
public class MyClass {

[Bindable]
public function set data(data:Object):void {
  this._data = data;
  dispatchEvent( new Event("dataChanged") );

Am I missing something?

Michael

Reply via email to