如何在Flex中的组件之间调度事件?
我是 Flex 的新手。我的问题是如何在组件之间分派事件?据我所知,Flex 只将事件冒泡到其自身或其父级。
我处于这样的情况:
<mx:Application>
<com:Component1 id="comp1" />
<com:Component2 id="comp2" />
</mx:Application>
在 Component2.mxml 中 我还有另外两个组件 A 和 B
我希望 comp1 调度一个带参数的事件,根据参数可以对 comp2 中的 A 和 B 进行一些更改。我怎样才能在 comp2 中获取事件?我知道 Cairngorm 可以做一个区别,但我现在不想使用它。有人可以帮我吗?非常感谢!
最好,硕
I'm new to Flex.My question is how to dispatch event between components?As far as I know,Flex only bubbles event to itself or its parent.
I'm in such a situation:
<mx:Application>
<com:Component1 id="comp1" />
<com:Component2 id="comp2" />
</mx:Application>
In Component2.mxml
I have two other components called A and B
I want comp1 to dispatch an Event with parameters,according to the parameters some changes could be made to A and B in comp2.How could I get the event in comp2?I know Cairngorm could make a difference,but I don't want to use it right now.Could anyone give me a hand?Much Thanks!
Best,Shuo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果应用程序触发冒泡事件,它将通过整个层次结构、comp1 和 comp2 以及它们各自的子级传递。 Comp1 应该携带元数据:
现在,当 comp1 调度事件时,它将在父级中进行处理,就像:
像中继一样。
我认为最好使用适当的 MVC 结构来处理这个问题,例如 Robotlegs、mate、swiz、PureMVC 等。
If Application fires a bubbling event it will be delivered through the entire hierarchy, comp1 and comp2 as well as their respective children. Comp1 should carry the metadata:
Now when comp1 dispatches the event, it will be handled in the parent like:
like a relay.
I think it is better to handle this with a proper MVC structure such as Robotlegs, mate, swiz, PureMVC, etc.
这非常很粗糙,但这就是你可以做到的。对于更复杂的情况,请在应用程序级别编写一个(或多个)函数,让它们处理事件,然后将您需要的内容传播给子级。在您的示例中,您需要在应用程序级别执行某些操作。
是的,正确的架构可能会更好。
That's very crude, but that's how you can do it. For more complicated cases, write a function (or functions) at the Application level, have those handle the events, and then propagate what you need down to the children. In your example you need to do something at the Application level.
Yes, a proper architecture is probably better.