Thanks for your reply Sam. I've tried this but it's still not working.
I assume by 'broadcast the event' you meant use dispatchEvent(), which
is what I did in the setter for the color of ToyTruck (with an event
named "itemChanged"). Then I changed the binding of the Text component
to be {_cartItem.getDescription()}, and I put the Binding metatag on
the getDescription() method of CartItem to be
[Bindable("itemChanged")]
public function getDescription():String { ... }
Are the minor differences I did from what you suggested a reason why
it's not working? I mean is there a difference between having the Text
component's binding being {_cartItem.toy.getDescription()} and
{_cartItem.getDescription()} ?
I guess I still don't understand how the above binding with a function
as the source gets called when you don't have an bindable argument of
the function. I keep rereading the Binding Data section of the Flex
DevGuide and the Binding sections of 'Creating And Extending Flex 2
Components' to try to understand how it's all wired together, but it's
not coming together for me.
--- In [email protected], "Samuel R. Neff" <[EMAIL PROTECTED]>
wrote:
>
>
> change your binding to be {_cartItem.toy.getDescription()} directly
(which
> is implied to work from your definition of Toy, but not the same as your
> original binding).
>
> Then change getDescription() to define a specific bindable event:
>
> [Bindable("getDescriptionChanged")]
> public function getDescription():String { ... }
>
> And then you need to broadcast the event "getDescriptionChanged"
anywhere
> that results in a change in value (i.e., never in the Toy base
class, but in
> the "color" setter for ToyTruck).
>
> HTH,
>
> Sam
>
>
> -------------------------------------------
> We're Hiring! Seeking a passionate developer to join our team
building Flex
> based products. Position is in the Washington D.C. metro area. If
interested
> contact [EMAIL PROTECTED]
>
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Brian
> Sent: Monday, December 10, 2007 11:01 AM
> To: [email protected]
> Subject: [flexcoders] help with 'deep' data binding
>
> I'm reposting this from late Friday afternoon, hope that's OK. I found
> a thread where something similar, and having to do with Cairngorm, was
> described as 'deep' data binding. I'd appreciate any help
>
> --- In [email protected], "Brian" <briforge@> wrote:
> >
> > I'm trying to bind a Text control to a function to get the description
> > of an item, when a property of a class inside that item changes. Is
> > this at all possible? I've tried different variations of binding
> > functions, Binding tags, etc. and still can't get it to work. Here are
> > code snippets that will hopefully explain what I'm trying to do.
> >
> > package src
> > {
> > [Bindable]
> > public class Toy
> > {
> > public getDescription():String {
> > // will be overridden in subclasses
> > return "";
> > }
> > }
> > }
> >
> > package src
> > {
> > [Bindable]
> > public class ToyTruck extends Toy
> > {
> > public var color:String;
> >
> > public override function getDescription():String {
> > return color + " truck";
> > }
> > }
> > }
> >
> > package cart
> > {
> > import src.*;
> > [Bindable]
> > public class CartItem
> > {
> > public var quantity:int
> > public var toy:Toy;
> >
> > public function getDescription():String {
> > return quantity + " " + toy.getDescription();
> > }
> > }
> > }
> >
> > MXML component
> > <mx:VBox>
> > <mx:Script>
> > <![CDATA[
> > import cart.CartItem;
> > import src.*;
> >
> > [Bindable]
> > public var _cartItem;
> >
> > public function getText(toy:Toy):String {
> > return _packItem.getDescription();
> > }
> > ]]>
> > </mx:Script>
> > <mx:Text id="itemDesc" text="{getText(_cartItem.toy)}"/>
> > </mx:Vbox>
> >
> > What I'd like to have happen is have the Text control update when the
> > ToyTruck.color is changed by other events. Is this possible? The above
> > code snippets is what I'm currently trying but the Tex is not
> > updating. Even though the toy is not used directly in the getText()
> > function, I thought having it as a parameter was how the function was
> > triggered. The docs say that when a bindable property as an argument
> > of the function changes, the function executes.
> >
> > In reality, there are different properties for different subclasses of
> > Toy, which could be modified by several different events. This is why
> > I'm trying to get the binding to work, so I don't have to manually
> > update the Text control all over the place. I thought that was the
> > whole point of Binding, but maybe I'm missing something.
> >
> > Or do I have to use a Binding tab for each of those different
> > properties of the subclasses? I haven't tried that yet but I don't
> > think that would work because the source has to be a string, right?
> >
> > Thanks
> >
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>