Flex 4 冒泡自定义事件
如何在 Flex 4 中创建冒泡自定义事件?
要在 MXML 中创建和公开自定义事件,您需要在将使用以下行调度事件的组件中声明它:
<fx:Metadata>
[Event(name="select", type="my.engine.events.SelectionEvent")]
</fx:Metadata>
这允许您:
<my:CustomComponent select="doSomething()"/>
但是,如何使该气泡向上。我想做这个
<s:DataGroup select="doSomethingForAll();">
<s:itemRenderer>
<fx:Component>
<my:CustomComponent/>
</fx:Component>
</s:itemRenderer>
</s:DataGroup/>
谢谢!
How to create a bubbling custom event in Flex 4?
To create and expose a custom event in MXML, you need to declare it at the component that will dispatch the event with this line:
<fx:Metadata>
[Event(name="select", type="my.engine.events.SelectionEvent")]
</fx:Metadata>
This allows you to:
<my:CustomComponent select="doSomething()"/>
However, how do you make this bubble upwards. I want to do this
<s:DataGroup select="doSomethingForAll();">
<s:itemRenderer>
<fx:Component>
<my:CustomComponent/>
</fx:Component>
</s:itemRenderer>
</s:DataGroup/>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的自定义事件必须扩展事件。在构造函数中,您会发现
name:string
、bubbling:boolean
和cacellable:boolean
作为参数。将冒泡参数设置为 true。在您的示例中,元数据标记必须位于您的数据组标记中。
Your Custom event must extend Event. On constructor you'll find
name:string
,bubbling:boolean
, andcacellable:boolean
as arguments.Set the bubbling parameter to true. In your example, the metadata tag must be in your DataGroup tag.
一种可能的解决方案(但不完全是我想要的)是在数据组级别添加这行代码。
这将确保 CustomComponent 触发的所有事件都不会发生。
One possible solution but not exactly what i was looking for is to add this line of code at the DataGroup level.
This will ensure all events fired by CustomComponent is cought.
您可以使用内置于扩展类中的指定自定义元标记数据信息来扩展 s:DataGroup 容器,也可以从 itemRenderer 的“select”事件处理程序中调用“doSomethingForAll()”方法,请参阅下面的代码:
You can either extend s:DataGroup container with specified custom metatag data information built-in into the extended class or you can either call "doSomethingForAll()" method from itemRenderer's "select" event handler, see code below:
捕获 dataGroups select 事件,然后调度 doSomethingForAll()
确保 doSomethingForAll 事件的冒泡属性设置为 true。
然后,在显示列表中侦听其上方的 doSomethingForAll 的任何事件侦听器都将被调用。
Catch the dataGroups select event and then dispatch a doSomethingForAll()
Make sure the doSomethingForAll event has it's bubbling property set to true.
Then any event listeners listening for doSomethingForAll above it in the display list will get called.