开发者

How can I access the implicit event dispatcher of a bindable Flex object?

开发者 https://www.devze.com 2022-12-22 10:42 出处:网络
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开发者_如何学Python I ac

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开发者_如何学Python I access that without making Foo explicitly extend EventDispatcher?


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号