The only difference in what you're doing in the two examples is declaring a
custom event in the second example. As Doug said, you can place the Binding
metadata tag over the getter or the setter, it makes no difference. If you
don't declare a custom event, an extra set of functions will be wrapped
around your getter/setter pair that uses the PropertyChangeEvent for
Binding. If you declare a custom event as you did in example 2, the compiler
will not generate the wrapper functions and you're required to dispatch the
declared event yourself. This is extremely useful as you can dispatch this
event anywhere in your class to trigger Bindings on a getter to fire.

I would reclassify your examples as 1) default Binding 2) Binding with
custom event

On Fri, Jun 27, 2008 at 5:32 PM, 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.html
>
>
> // Binding #1
> [Bindable]
> public function set shortNames(val:Boolean):void {
>     ...
> }
> public function get shortNames():Boolean {
>     ...
> }
>
> I did glean a trick for read-only binding for static data by using:
> public static const constString:String="A static const.";
>
> However, I still need to clear up one thing. Is it true that you can place
> [Bindable] meta data on either a setter of getter and have it bound to a
> View component?
>
>
>
>
>
>
> --- In flexcoders@yahoogroups.com, "Doug McCune" <[EMAIL PROTECTED]> wrote:
> >
> > If you define a getter and a setter you can add the [Bindable] metadata
> to
> > either the getter or setter, it does the same thing either way. The only
> > time you have to use a custom event to trigger the binding is when you
> have
> > read-only properties (a getter but no setter).
> >
> > Doug
> >
> > On Fri, Jun 27, 2008 at 12:08 PM, securenetfreedom [EMAIL PROTECTED] wrote:
> >
> > > Any thoughts?
> > >
> > >
> > > In an DataModel class what is the best way to bind data.
> > >
> > > 1) Make the Setter Bindable, or
> > > 2) Make the Getter Bindable and dispatch an event on the Setter?
> > >
> > > What are the advantages and disadvantages of each?
> > >
> > > // Binding #1
> > > [Bindable]
> > > public function set foo(val:String):void{
> > > _foo = val;
> > > }
> > > public function get foo():String{
> > > return _foo;
> > > }
> > >
> > > // Binding #2
> > > [Bindable(event="fooChanged")]
> > > public function get foo():String{
> > > return _foo;
> > > }
> > > public function set foo(val:String):void{
> > > _foo = val;
> > > dispatchEvent(new Event(MyDataModel.FOO_CHANGED));
> > > }
> > >
> > >
> > >
> >
>  
>

Reply via email to