Flex的中继器和EventListeners的 [英] Flex Repeaters and EventListeners

查看:95
本文介绍了Flex的中继器和EventListeners的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

乍一看,Repeater控件看起来非常强大,但现在我后悔了。

At first glance, the Repeater control looks extremely powerful, but now I'm having second thoughts.

在眼前问题: 添加事件监听器给孩子

Problem at hand: Adding Event Listeners to the children

直放站对象是通过一个ArrayCollection创造新的VBOX的孩子每个项目必然要和迭代。现在对于每个孩子,Repeater对象将把火关重复活动,在那里我很想加入的事件监听器(鼠标事件)。没有问题,到目前为止,但什么时候ArrayCollection的变化,我应该怎么删除EventListeners的所有旧的孩子怎么办?有没有包含我VBOX情况下的孩子,我的文档跳过的阵列?正在EventListeners的清理很好,当他们连接到被销毁的对象?

Repeater object is bound to and iterates through an ArrayCollection creating new Vbox children for each item. Now for each child, the Repeater object will fire off a "repeat" event, where I'm tempted to add the eventlistener (for mouse events). No problems so far, but, what happens when the ArrayCollection changes, how should I remove the EventListeners for all the old children? Is there an array of children containing my Vbox instances that I'm skipping over in the docs? Are eventlisteners cleaned up nicely when the object they are attached to is destroyed?

-C codeR失去了弹性/动作

-C coder lost in flex/actionscript

推荐答案

我会避免使用中继器完全。从性能的角度来看,他们都非常缓慢,因为项目经常被破坏并重新创建。你最好使用一个清单为基础的控制和实施的itemRenderer。

I would avoid using Repeaters entirely. From a performance standpoint they are very slow because the items are frequently destroyed and recreated. You are better off using a List-based control and implementing an itemRenderer.

事件侦听器在默认情况下是强引用,所以如果你不删除你的事件侦听器,将prevent被垃圾收集的对象。您可以使用可选的第五个参数名为WeakReference的使用addEventListener并将其值设置为true以添加一个事件监听器不会prevent GC。

Event listeners by default are strong references, so if you do not remove your event listeners it will prevent the object from being garbage collected. You can use the optional 5th parameter in the addEventListener called "weakReference" and set the value to true to add an event listener that will not prevent GC.

要更好地应对在itemRender组件事件,可以实现IDropInListItemRenderer接口。这将使你获得的ListData里面有一个所有者属性,它是实际的表对象本身。在您的itemRenderer,派遣载有必要的数据通过业主的自定义事件。如果事件侦听器添加到列表控制它的创建后,那么你可以做的事件处理中包含控件的组成部分。

To better deal with events in your itemRender component, you can implement the IDropInListItemRenderer interface. This will give you access to "listData" which has an "owner" property which is the actual List object itself. In your itemRenderer, dispatch a custom Event containing the necessary data through the owner. If you add an event listener to the List control after it's created then you can do the event handling in the component containing the control.

这篇关于Flex的中继器和EventListeners的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆