views:

33

answers:

1

I have this variable in Model class:

[Bindable]
public var someXml:XML;

I've used BindingUtils to get notified when the XML changes:

BindingUtils.bindSetter(onChange, Model.getInstance(), "someXml");

private function onChange(value:Object):void {
    // do something
}

Function onChange gets triggered when I assign an XML to the variable, but not when I change some attribute of the XML:

Model.getInstance().someXml.@attr = "newValue";

Why?

+2  A: 

Because XML isn't an EventDispatcher and so doesn't dispatch Change Events when it's contents change. It descends directly from Object, so there's no EventDispatcher.

Gregor Kiddie
ah yes, that makes sense.
Strudel
do you know a way to bind XML attributes?
Strudel
I don't think there's a direct way of doing it. My suggestion would be to encapsulate the change you want to make to the xml in a method on the model, so you can dispatch the change event from the model and get the binding to fire that way. Model.getInstance().updateXML( attrName, newValue );
Gregor Kiddie