1
votes

I've got a XML object that is shared by some components. Is it possible to set a BindSetter to a specific tag and call a function if that property changes?

I've tried it, but the BindSetter call doesn't seem to accept XML tag names.

When simply using [Bindable] and using the the tag name in MXML (i.e. label text="{myXMLObject.tagName}") this works fine, so I figure this has to work in pure AS as well, I just haven't figured out how.

Any hints?

Based on the comments/answer, here is a very basic example of my code/usage.

Two components in a Flex app, both inherit the same XML object;

[Bindable] public var sharedData:XML;

Then in the creationComplete handler of every component, I call the BindSetter;

BindingUtils.bindSetter(sharedDataChange, sharedData, "tagName");

sharedDataChange doesn't do anything at this point, just tracing that the function has been called.

I've then got a Label that displays the value of sharedData.tagName, a textInput and a button that sets sharedData.tagName = textInput.text. Using MXML binding ({label.text = sharedData.tagName}) this works fine. But as I said, the BindSetter function doesn't seem to detect the changes.

1
maybe someone else can explain directly how to do this to you but you may want to look at just doing a -keep to get the generated actionscript then use some sort of diff viewer to see the difference between two simple Flex apps with the only difference being one of the xml type bindings you're looking for. Also you should post some code. - shaunhusain
Can you post, how did you write bindSetter for myXMLObject.tagName? - Engineer

1 Answers

0
votes

If label text="{myXMLObject.tagName}" works for you, then

 BindingUtils.bindSetter(function(value:*):void{
     //Do something
 }, this, ["myXMLObject","tagName"]);  

should work as well, but myXMLObject must be 'public'.

There is no difference for BindingUtils whether it is working with XML or with some other object. If object is specified as [Bindable], then BindingUtils will work with it correctly.

UPDATE: There is a big difference between

BindingUtils.bindSetter(sharedDataChange, sharedData, "tagName"); 

and

BindingUtils.bindSetter(sharedDataChange, this, ["sharedData", "tagName"]);

If you will write something 'shareData = ...' , the setter of first expression will not be called,but for the second one, it will be.