为什么我们使用“气泡”?在弹性活动中
我怀疑我们何时在 Flex 中创建自定义事件。
为什么我们在 Flex 事件中使用 'type:String, bubbles:Boolean=false, cancelable:Boolean=false' 这些参数。
I've doubt when we create custom event in flex.
Why do we use 'type:String, bubbles:Boolean=false, cancelable:Boolean=false' these parameter in flex events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
冒泡导致已调度的事件继续沿显示树向上调度,直到到达舞台。这在各种场景中都很有用。
例如:假设您的父 DisplayObject 中有多个按钮。您可以向每个按钮添加侦听器,并记住随后将其删除,或者您可以只向父级添加一个侦听器。这是有效的,因为 MouseEvents 启用了冒泡。
这样做的好处是您现在可以自由添加和删除按钮,而不必担心向它们附加侦听器。事件对象的
target
属性将是对被单击按钮的引用,而currentTarget
将是对父级的引用。Cancelable 是一个标志,用于设置是否允许您通过调用
preventDefault()
方法来停止事件的默认操作。Bubbling causes a dispatched event to continue to be dispatched up the display tree until it reaches the stage. This is useful in various scenarios.
For example: Imagine you have several buttons inside a parent DisplayObject. You could add listeners to each button, and remember to remove them afterwards, or you could just add one listener to the parent. This works because MouseEvents have bubbling enabled.
The benefit of this is that you can now add and remove buttons freely, without having to worry about attaching listeners to them. The
target
property of the event object will be a reference to the button that was clicked, andcurrentTarget
will be a reference to the parent.Cancelable is a flag that sets whether or not you are permitted to stop the default action of an event by calling the
preventDefault()
method.