This still wasn't working. I noticed while debugging that the method
that was supposed to be listening to the 'descriptionChanged' was
still never being called. I wondered if it had something to do with
extending EventDispatcher, so I modified Toy to extend EventDispatcher
and the listening method was still not being called. So I dug into
EventDispatcher a bit and found another thread here that was exactly
what I was looking for, titled 'Events and Non-Display Objects' : 

http://tech.groups.yahoo.com/group/flexcoders/message/95122

The Singleton 'SystemEventManager' is much simpler and I used that to
get it working. In fact I already had a similar class in my app for a
different event. It seems like the Binding model quickly gets far too
complicated when not dealing with top-level classes.

Thanks again for your help Sam.

Brian

--- In flexcoders@yahoogroups.com, "Samuel R. Neff" <[EMAIL PROTECTED]>
wrote:
>
> You'll need to add the Bindable metadata to both getDescription on
Toy() as
> well as CartItem() and within your CartItem class you need to listen
for the
> changed event within Toy and rebroadcast a new changed event from
CartItem
> when the contained Toy change it's description.
> 
> HTH,
> 
> Sam
> 
> 
> public class Toy extends EventDispatcher {
>    [Bindable("descriptionChanged")]
>    public function getDescription():String {
>      return ""; // assume is overridden in child class, which also
> broadcasts descriptionChanged
>    }
> }
> 
> public class CartItem extends EventDispatcher {
> 
>   private var _quantity:uint;
>   [Bindable("quantityChanged")]
>   public function get quantity():uint {
>     return _quantity;
>   }
>   public function set quantity(value:uint):void {
>     _quantity = value;
>     dispatchEvent(new Event("quantityChanged"));
>     dispatchEvent(new Event("descriptionChanged"));
>   }
>   
>   private var _toy:Toy;
>   [Bindable("toyChanged")]
>   public function get toy():Toy {
>     return _toy;
>   }
>   public function set toy(value:Toy):void {
>     if (_toy) {
>       _toy.removeEventListener("descriptionChanged",
> rebroadcastDescriptionChanged);
>     }
>     _toy = value;
>     if (value) {
>       value.addEventListener("descriptionChanged",
> rebroadcastDescriptionChanged);
>     }
>     dispatchEvent(new Event("toyChanged"));
>   }
> 
>   private function rebroadcastDescriptionChanged(event:Event):void {
>     dispatchEvent(new Event("descriptionChanged"));
>   }
> 
>   [Bindable("descriptionChanged")]
>   private function getDescription():String {
>     return quantity + " " + toy.getDescription();
>   }
> }
> 
> 
> -------------------------------------------
> 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]
>


Reply via email to