This content has been marked as final. Show 3 replies
Hi!, i just would like to know if you have solved the problem with the binding. At this moment, i have the same problem, exactly how you did explain it.
Please, if you could help me, i will apreciate it!
Hi.. could you solve the problem with the bindsetter???
I still have problem with that and i must solve as soon as posible...
Yes, I believe so. It involves a slight modification of the bindproperty static function to take an additional parameter (your function). Data changes in the source are funneled into the passed function and then to the target property. Disclaimer: I do not know if this code is 100% the best way to do this, but it seems to work for me in my initial testing. I have NOT tested this completely! Give it a try though.
internal function bindPropertywithFunction(
commitOnly:Boolean = false,
var w:ChangeWatcher =
ChangeWatcher.watch(host, chain, null, commitOnly);
if (w != null)
var assign:Function = function(event:*):void
site[prop] = w.getValue();
assign(null); // Initialize value in target thru myfunc
and you would use it by creating a changewatcher for each instance of your control:
// Perform some function on the value before assigning
// it to the target
Note that I added the function after the commitOnly parameter to maintain consistency. If you do not use a function then the above code should act the same as bindProperty.
Also, even though this does what I wanted, I am not sure how efficient it is to create a changewatcher for each instance of a control. If we assume that we create controls in a loop then perhaps the bindSetter would work if we kept an external array of references to the control instance list. (This is, of course, assuming that all controls in the loop would pass through the same kind of transformation). In other words, as each control is instantiated, I push its instance to an array, and then in the bindSetter function, use that array to take the changed value, modify it, and pass to each instance in the array. Just another idea.
However, adding a unique changewatcher is useful if each control's value is dependent on some other value as determined during the instantiation loop.