explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!

A common {Binding} issue and a work around.


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:

  1. Instead of [Bindable], use [Bindable (event="myCustomEventName")] on your getter.
  2. Make sure the related setter dispatches the event like so: dispatchEvent(new Event("myCustomEventName"));
  3. Also making sure to add [Event (name="myCustomEventName", type="flash.events.Event")] for any external listeners.
  4. 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 thoughts on “A common {Binding} issue and a work around.

  1. 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!

  2. Correct. 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’);

  3. Pingback: Tips (and reckless behaviour) for Component Developers « jwopitz - flex/flash exploration

  4. I 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



  5. Oh, and did not know about it. Thanks for the information …

  6. Does anyone have a more complete example of solving this binding proble? I’m facing the same, and having problem to find a solution.
    Thanks for any info!

  7. 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…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s