views:

84

answers:

1

If I create an object like so:

class Foo {
    [Bindable] public var property: String;
}

The class Foo has an implicit event dispatcher to handle property change events. How can I access that without making Foo explicitly extend EventDispatcher?

+2  A: 

If you add the -keep parameter to your compile line you will be able to see what it generates. But to explain it quickly you can just handle it like it would be a regular EventDisaptcher.

So in your main file you can paste this:

function callFirst(event:FlexEvent):void
{
   foo.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE,test);
   foo.property = 'something';
}

function test(E:Event):void
{
   trace (ObjectUtil.toString(E));
}

Will print out:

(mx.events::PropertyChangeEvent)#0
  bubbles = false
  cancelable = false
  currentTarget = (Foo)#1
    property = "something"
  eventPhase = 2
  kind = "update"
  newValue = "something"
  oldValue = (null)
  property = "property"
  source = (Foo)#1
  target = (Foo)#1
  type = "propertyChange"
Robert Bak
I'm thinking from within Foo; I think what was confusing me was that the code completion support in Flash Builder will not propose dispatchEvent as a completion, but it compiles fine. Okay, thanks!
Chris R