Flex 2 Observer Problems? Make sure the observed variable actually changes.
If you’re using an Observer in Flex 2, but its handler doesn’t seem to be executing when you’d expect it to, make sure that the variable the Observer watches isn’t getting reset to the same value it already has. In this case, the Observer’s handler function won’t run.
Example: pretend that A and B are empty arrays. C is an array reference, currently null. D is an Observer, observing C. D’s handler does this: whenever C is set to an array, a random number is added to that array. Now pretend C is set from null to array A. The handler adds a random number to A, as expected. Now, C is set to array B. A random number is added to B. Now, and here’s the part to be careful about, assume C is again set to B — even that’s the same value it already has. Nothing happens! No random number will be added to B, and when we print out our arrays A and B at the end of the program, we’ll be a little confused why we see two instead of three values.
Dumb example? Yes. Obvious? Yes. Easy to get tripped up by and waste time on? Yes.
There you have it, kids.
Loading...
Yup… hate this one. Same thing going on here: http://thillerson.wordpress.com/2006/12/13/psa-bindable-setters-dont-fire/
Tony Hillerson - June 11, 2007 at 4:14 am