何时扩展 EventDispatcher
简单的问题..我想知道你们什么时候在班级中扩展 EventDispatcher 。在我看来,只要我们有导入事件包,我们就可以毫无问题地调度事件......我有时看到人们在他们的类中扩展EventDispatcher......不知道为什么......有人愿意解释一下吗?谢谢一百万...
Simple question..I was wondering when you guys extends EventDispatcher in your class. It seems to me that as long as we have import event package, we can dispatchEvent without problems....I saw sometime people extends EventDispatcher in their class...not sure why...anyone care to explain? Thanks a million...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能会感到困惑,AS3 中的许多对象在继承树中扩展了 EventDispatcher,只需要导入 flash.events 包即可分派事件。例如,许多 DisplayObject 类扩展了 EventDispatcher。这里有几个例子:
通常,每当我使用自定义类时,我都会扩展 EventDispatcher,该自定义类只需要与其范围之外的对象进行通信,了解某些内部属性已更改或某些功能正在发生。这是一个例子:
有时保持对象的内部细节只读是“重要的”。在上面的示例中,当调用
run()
方法时,Clock
类执行一些内部逻辑,然后调度一个事件来指示某些内容已发生更改。然后,任何侦听该事件的类都可以调用公共getTick()
方法来查找_tick
的值。这隐藏了实现并保护_tick
变量不被外部类更改,同时提供了一个可以读取Clock
的接口。I think you might be confusing the fact that many objects in AS3 extend EventDispatcher higher in the inheritance tree with only needing to import the flash.events package in order to dispatch events. For instance many DisplayObject classes extend the EventDispatcher. Here are a couple of examples:
Typically I will extend EventDispatcher any time I am working with a custom class that just needs to communicate to objects outside of it's scope that some internal property has changed or that some function is occuring. Here is an example:
Sometimes it is "important" to keep the internal details of an object read only. In the case of the above example, when the
run()
method is called, theClock
class performs some internal logic and then dispatches an event indicating that something has changed. Any class that is listening for that event can then call the publicgetTick()
method to find out the value of_tick
. This hides the implementation and protects the_tick
variable from being changed by outside classes and at the same time provides an interface through which theClock
can be read.