RE: [flexcoders] Re: Best Practice Data Binding

2008-07-01 Thread Rick Winscot
When working in mxml you can use the -keep-generated-actionscript compiler
option. and in the 'generated' directory you will find a wealth of
information!

 

In short - the answer you seek is before you! Finding the 'solution' is
another story. 

 

Rick Winscot

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of mauricen
Sent: Tuesday, July 01, 2008 8:42 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Best Practice Data Binding

 

Thanks very much for your time in writing this; it's very helpful. But
my question still stands: if there are parts of your answer that I
don't understand fully, or that raise more questions in my mind (and
both of these are in fact the case), how do I resolve these
difficulties? How did you learn about this (aside from the LiveDocs,
I mean)? The implementation must be defined *somewhere*, surely, even
if only in code?

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ,
Josh McDonald [EMAIL PROTECTED] wrote:

 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 flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
, securenetfreedom nv1000@ 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\ht
tp://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\ht
tp://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]


 



Re: [flexcoders] Re: Best Practice Data Binding

2008-07-01 Thread Josh McDonald
Honestly, fucked if I know how I picked all this stuff up - it's just what I
do. But if my explanation left something out, that's my fault for giving a
shitty explanation. Tell me in detail what you're still confused about, and
I'll try and explain it :)

-Josh

On Tue, Jul 1, 2008 at 11:14 PM, Rick Winscot [EMAIL PROTECTED]
wrote:

  When working in mxml you can use the –keep-generated-actionscript
 compiler option… and in the 'generated' directory you will find a wealth of
 information!



 In short – the answer you seek is before you! Finding the 'solution' is
 another story.



 Rick Winscot







-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]


RE: [flexcoders] Re: Best Practice Data Binding

2008-07-01 Thread Stephen Gilson
Hi Maurice,
 
You can see the doc on binding here:
http://livedocs.adobe.com/flex/3/html/databinding_1.html
http://livedocs.adobe.com/flex/3/html/databinding_1.html 
 
For infomration about creating bindable properties in custom MXML
components, see this page:
http://livedocs.adobe.com/flex/3/html/mxmlcomponents_advanced_3.html
http://livedocs.adobe.com/flex/3/html/mxmlcomponents_advanced_3.html 
 
For information on creating bindable properties in custom AS components:
http://livedocs.adobe.com/flex/3/html/ascomponents_3.html
http://livedocs.adobe.com/flex/3/html/ascomponents_3.html 
 
Stephen



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of mauricen
Sent: Monday, June 30, 2008 6:20 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Best Practice Data Binding



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 flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
, 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.h
t  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
  tml



 


RE: [flexcoders] Re: Best Practice Data Binding

2008-07-01 Thread Rick Winscot
Josh - I second Jeff's comment and have to apologize if my response was
sour. What I was trying to say is that, given your example, I would think
that the path was clear for the poster to 'have at it.' It isn't necessary
to understand (to perfection) how binding works to use it. or to begin
experimenting with behavior/performance to find a best practice. Is there a
definitive/single way to implement binding? No. Can one implementation
perform better than another? Of course! Where should the original poster
begin their search for ultimate truth? Your suggestion is worthy of a
cut-and-paste starting point - and as you say. the deeper understanding will
happen with time and perhaps after you bleed at the keyboard for hours on
end.

 

Rick Winscot

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of securenetfreedom
Sent: Tuesday, July 01, 2008 4:39 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Best Practice Data Binding

 

Josh,

That's one of the better explanations I've seen on the subject. It
fills the blanks left by
http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.html.

Thanks for the contribution.

And BTW, the keyboard is a bad place to be while consuming adult
beverages, partaking in a controlled substance, or after finishing a
fight... it leaves a pretty ugly permanent mark on the post. ;)

Jeff

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ,
Josh McDonald [EMAIL PROTECTED] wrote:

 Honestly, fucked if I know how I picked all this stuff up - it's
just what I
 do. But if my explanation left something out, that's my fault for
giving a
 shitty explanation. Tell me in detail what you're still confused
about, and
 I'll try and explain it :)
 
 -Josh
 
 On Tue, Jul 1, 2008 at 11:14 PM, Rick Winscot [EMAIL PROTECTED]
 wrote:
 
  When working in mxml you can use the -keep-generated-actionscript
  compiler option. and in the 'generated' directory you will find a
wealth of
  information!
 
 
 
  In short - the answer you seek is before you! Finding the
'solution' is
  another story.
 
 
 
  Rick Winscot
 
 
 
 
 
 
 
 -- 
 Therefore, send not to know For whom the bell tolls. It tolls for
thee.
 
 :: Josh 'G-Funk' McDonald
 :: 0437 221 380 :: [EMAIL PROTECTED]


 



Re: [flexcoders] Re: Best Practice Data Binding

2008-07-01 Thread Josh McDonald
Heh :)

I don't think there was anything at all wrong with your response mate,
although the generated directory can be a scary place, there's a *lot* of
actionscript classes that go into making a Flex swf do its thing.

I do apologise if I come off as a jerk, but I can't apologise for the
occasional curse word. I'm one of those types who don't really believe in
freedom from being offended. I didn't punch anybody's mum, or sleep with
their sister or anything ;-)

-Josh

On Wed, Jul 2, 2008 at 10:21 AM, Rick Winscot [EMAIL PROTECTED]
wrote:

  Josh – I second Jeff's comment and have to apologize if my response was
 sour. What I was trying to say is that, given your example, I would think
 that the path was clear for the poster to 'have at it.' It isn't necessary
 to understand (to perfection) how binding works to use it… or to begin
 experimenting with behavior/performance to find a best practice. Is there a
 definitive/single way to implement binding? No. Can one implementation
 perform better than another? Of course! Where should the original poster
 begin their search for ultimate truth? Your suggestion is worthy of a
 cut-and-paste starting point – and as you say… the deeper understanding will
 happen with time and perhaps after you bleed at the keyboard for hours on
 end.



 Rick Winscot





-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]


Re: [flexcoders] Re: Best Practice Data Binding

2008-07-01 Thread Josh McDonald
I wasn't being a jerk here (or angry about anything). If I put effort into
an explanation and it doesn't actually clear up the question, I wanna know
about it so I can add to it, and hopefully do a better job next time.

-Josh

On Wed, Jul 2, 2008 at 12:22 AM, Josh McDonald [EMAIL PROTECTED] wrote:

 Honestly, fucked if I know how I picked all this stuff up - it's just what
 I do. But if my explanation left something out, that's my fault for giving a
 shitty explanation. Tell me in detail what you're still confused about, and
 I'll try and explain it :)

 -Josh




-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]


Re: [flexcoders] Re: Best Practice Data Binding

2008-06-30 Thread Josh McDonald
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 flexcoders@yahoogroups.com, 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]


Re: [flexcoders] Re: Best Practice Data Binding

2008-06-28 Thread Daniel Gold
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));
   }
  
  
  
 
  



Re: [flexcoders] Re: Best Practice Data Binding

2008-06-27 Thread Richard Rodseth
I do 2) all the time. Didn't know 1) was even an option.

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));
 }

 


Re: [flexcoders] Re: Best Practice Data Binding

2008-06-27 Thread Doug McCune
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));
 }

  



RE: [flexcoders] Re: Best Practice Data Binding

2008-06-27 Thread Alex Harui
Last time I looked, #1 wrapped your getter setters in another pair of
function which is somewhat wasteful.  That's why you'll never see
pattern #1 in the framework code.

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Doug McCune
Sent: Friday, June 27, 2008 1:21 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Best Practice Data Binding

 

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]
mailto:[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));
}