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" <[EMAIL PROTECTED]> 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




Reply via email to