If you are relying on the built in Flex binding mechanism, you may have run into this issue: The Binding won’t update its listeners if the value you are setting the property to is the same as the previous value. Put another way:
var a:Number = 10;
trace(a); //firing the getter which outputs 10.
a = 10; //firing the setter, bindings will not update listeners.
Do not rely on Flex to fire the propertyChangeEvent w/ respect to the related getter/setter by using the default [Bindable] metatag. Instead modify your class with these steps:
- Instead of
[Bindable], use[Bindable (event="myCustomEventName")]on your getter. - Make sure the related setter dispatches the event like so:
dispatchEvent(new Event("myCustomEventName")); - Also making sure to add
[Event (name="myCustomEventName", type="flash.events.Event")]for any external listeners. - Implement custom logic on the listeners in questions so that they can be updated via the event rather than the binding.*
How this might assist you? Well rather than relying on having to circumvent the binding not firing when setting the property to the same value, you could have additional listeners for that custom event since it is fired regardless of the previous set value.
*Although I do use this method on all of my getters/setters, I would not necessarily implement the external logic on all of the bound listeners. I would only do so in cases where the property needs to be updated regardless of whether or not the new value is the same as its previously set value.
7 Comments so far
Leave a comment
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

I’m pretty sure the default change event is propertyName + “Change”, so if your property was “firstName”, then you’d just dispatch “firstNameChange”… or was it past-tense, “firstNameChanged”. Anyway, no need make your own event if you can figure out if it has the d or not, hehe!
Comment by JesterXL Thursday, March 29, 2007 @ 6:32 pmCorrect. I wasn’t implying that you need to make an Event subclass, I am simply suggesting, as you have reiterated, to create your own event type as shown in the code example up above. So new Event(‘newEventType’);
Comment by jwopitz Thursday, March 29, 2007 @ 6:42 pm[...] you’d make use of enumeration property in the Style metatag. Also, anyone who has read my post on Flex’s built in Binding mechanism might want to implement their own custom event/binding [...]
Pingback by Tips (and reckless behaviour) for Component Developers « jwopitz - flex/flash exploration Wednesday, April 25, 2007 @ 9:27 pmI faced a similar problem with binding when implementing a read-only data model. Check it out here: http://adamflater.blogspot.com/2007/08/binding-with-getters-and-setting.html
-adam
———-
Comment by Adam Flater Thursday, August 23, 2007 @ 10:07 pmhttp://adamflater.blogspot.com
Oh, and did not know about it. Thanks for the information …
Comment by Andy Wednesday, December 19, 2007 @ 4:55 pmDoes anyone have a more complete example of solving this binding proble? I’m facing the same, and having problem to find a solution.
Comment by Romain Tuesday, October 28, 2008 @ 4:02 pmThanks for any info!
it dosnt’ works if you have getter function in a class and use this function as a dataprovider then making any change it dataprovider is updated same in getter property too…
Comment by sanjeev Wednesday, March 25, 2009 @ 7:47 am