2

嗨,我有一个带有 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 都是空的。

为什么会这样?

4

2 回答 2

3

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

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

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

这现在有效。不知道为什么它不适用于位图

于 2010-05-20T19:08:43.877 回答
0

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

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

您可能还遇到了itemRenderer recycling的问题。您可能想要覆盖public function set data()并处理在那里设置单个项目属性,而不是依赖绑定。

您在哪里查看 arrayCollection 以查看 bitmapData 为空?

于 2010-05-20T18:45:50.590 回答