The authoritive story is pretty much as Daniel said:
[Bindable]
public var myField:String;
The above will generate something the equivalent of:
mx_internal var _myField:String; //Might be private, can't be arsed to check
[Bindable event="propertyChangeEvent"]
public function get myField():String {
return _myField;
}
public function set myField(value:String):void {
if (value != _myField) {
var oldVal:* = _myfield;
_myField = value;
dispatchEvent(new PropertyChangeEvent(this, "myField", oldVal, newVal));
}
}
And if you put the generic [Bindable] on a getter _or_ a setter, you'll
re-generate the above code, but _myField will be the original get/set
functions renamed, not a private or mx_internal var.
As a rule, I don't use the generic [Bindable] on getter/setter functions.
It's just not that hard to dispatch an event.
However if you're going to put generic [Bindable] on a getter/setter pair,
put it on the *setter*. Otherwise the debugger will hilight the getter
method when you're single-stepping through foo.myField = "someValue" - it's
not a law or anything, but it's confusing even when you know why it does it.
When you're using a custom event, put the [Bindable(event="myEventName")] on
the *getter*. That way you always know it's bindable, as not every getter
needs a setter. You can dispatch the event from anywhere you please, either
a setter method or something else. Don't know about performance, but when
you're not using a PropertyChangeEvent, bindings will fire for anything
matching that name, since it can't use the fieldName and object properties
of PropertyChangeEvent to know exactly which field should re-fire bindings.
One last thing, you can specify [Bindable(event="PropertyChangeEvent")] on a
getter, and you'll still need to dispatch your own PropertyChangeEvents from
the setter or from anywhere else. It lets you be a specific as to what's
changed in the object without having a bunch of custom named events.
Disclaimer: I'm 99% sure that's all correct. YMMV ;-)
-Josh
On Tue, Jul 1, 2008 at 8:19 AM, mauricen <[EMAIL PROTECTED]> wrote:
> Where *is* the authoritative story on binding? As a newcomer to Flex
> I'm finding it hard to form a coherent picture of how the various
> binding features fit together. What's the mechanism, for example,
> that allows me to call addEventListener on a Bindable property? If
> there's no formal documentation, I'd be happy to look at code - but where/
>
> Maurice
>
> --- In [email protected], "securenetfreedom" <[EMAIL PROTECTED]>
> wrote:
> >
> > I found this page to be helpful but not authoritative (This is where I
> > found the use of binding the setter);
> >
> http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.ht\<http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.ht%5C>
> > ml
> >
> <http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.h\<http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.h%5C>
> > tml>
>
>
>
> ------------------------------------
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
> Links
>
>
>
>
--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."
:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]