【问题标题】:Flex List ItemRenderer with image loses BitmapData when scrolling滚动时带有图像的 Flex List ItemRenderer 丢失 BitmapData
【发布时间】:2010-05-20 18:35:22
【问题描述】:

您好,我有一个带有 DataProvider 的 mx:List。如果 FotoItems,此数据提供程序是 ArrayCollection

public class FotoItem extends EventDispatcher
{
    [Bindable]
    public var data:Bitmap;
    [Bindable]
    public var id:int;
    [Bindable]
    public var duration:Number;

    public function FotoItem(data:Bitmap, id:int, duration:Number, target:IEventDispatcher=null)
    {
        super(target);
        this.data = data;
        this.id = id;
        this.duration = duration;
    }
}

我的 itemRenderer 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" >
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
    ]]>
</fx:Script>

<s:Label text="index"/>
<mx:Image source="{data.data}" maxHeight="100" maxWidth="100"/>
<s:Label text="Duration: {data.duration}ms"/>
<s:Label text="ID: {data.id}"/>

</mx:VBox>

现在当我滚动时,所有离开屏幕的图像都会消失:( 当我查看 arrayCollection 时,每个项目的 BitmapData 都是空的。

为什么会这样?

【问题讨论】:

    标签: apache-flex flash data-binding list itemrenderer


    【解决方案1】:

    我将 FotoItem 类中数据的数据类型从 Bitmap 更改为 BitmapData

    在 ItemRenderer 中,我执行以下操作:

    override public function set data( value:Object ) : void {
                super.data = value;
                pic.source = new Bitmap(value.image);
            }
    

    现在可以了。不知道为什么它不适用于位图

    【讨论】:

    • 如果您最初用于实例化数据的值是 BitmapData 类型,这可以解释为什么 Bitmap 值返回为空。您不能只将 BitmapData 分配给 Bitmap 并让它自动转换。
    【解决方案2】:

    我认为这可能与您对 data.data 的使用有关 - 我认为 data 是 Actionscript 中的保留关键字,最好将您的图像属性命名为其他名称,例如 data.imageData。

    我也不确定为什么要将 ArrayCollection 导入项目渲染器,因为您似乎没有在 itemRenderer 中使用它。

    您也可能遇到itemRenderer recyling 的问题。您可能希望覆盖 public function set data() 并在那里设置单个项目属性,而不是依赖绑定。

    你在哪里看 arrayCollection 看 bitmapData 是空的?

    【讨论】:

    • 我尝试将 data.data 更改为其他内容,但这不起作用。我没有在我的渲染器中使用 arrayCollection。数据提供者是一个arrayCollection。我也认为这与回收有关。但它不应该改变 arrayCollection 中的数据,不是吗?我正在查看调试视图中的数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 2015-05-14
    • 2011-09-30
    • 2012-01-21
    相关资源
    最近更新 更多