带有元数据 [Bindable] 关键字的基类是否会自动扩展 EventDispatcher?

发布于 2024-12-07 10:14:33 字数 605 浏览 0 评论 0原文

我遇到了一些奇怪的事情,但也许其他人以前也遇到过这个问题。

我有一个基类,它不扩展任何东西。让我们称之为...

public class FooBar {
    //...
}

但我想绑定它的每一个公开属性:

[Bindable] public class FooBar {
    public var propertyOne:String;
    public var propertyTwo:String;
}

在调试/分析类时,我注意到每次更改属性时 - FooBar 的实例是对其调用“.dispatchEvent()”。但我的类没有扩展EventDispatcher

什么给?

这是否意味着,在编译时,我的类会自动扩展 EventDispatcher 或其他具有调度事件能力的类?如果我的类没有声明“addEventListener”方法,我如何监听PropertyChangeEvent

I'm encountering something a bit bizarre, but maybe someone else came across this before.

I've got a base class, that doesn't extend anything. Let's call it...

public class FooBar {
    //...
}

But I want to bind EVERY single one of its exposed properties:

[Bindable] public class FooBar {
    public var propertyOne:String;
    public var propertyTwo:String;
}

While Debugging / Profiling the class, I'm noticing that each time a property is changed - the instance of FooBar is calling ".dispatchEvent()" on it. But my class doesn't extend EventDispatcher.

What gives?

Does this mean, at compile time, my class automatically extends EventDispatcher or some other class with the ability to dispatch events? How could I listen to the PropertyChangeEvent if my class doesn't have the "addEventListener" method declared in it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2024-12-14 10:14:33

当您使用[Bindable]元数据时,Flex编译器会为您生成大量代码。如果您想知道到底发生了什么,请查看 的答案Flex [Bindable] 标签有什么作用? 以及发布在那里的链接。

回答你的问题:不,你的类没有扩展EventDispatcher。但是,编译器会更改您的类,以便它将实现 IEventDispatcher 接口。该接口的生成实现使用 EventDispatcher 的实例。

When you use the [Bindable] metadata the Flex compiler generates a lot of code for you. If you want to know what happens exactly take a look at the answers to What does the Flex [Bindable] tag do? and the links that are posted there.

To answer your question: No, your class doesn't extend EventDispatcher. However, the compiler changes your class so that it will implement the IEventDispatcher interface. The generated implemenation of that interface uses an instance of EventDispatcher.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文