开发者

Flex List ItemRenderer with image loses BitmapData when scrolling

Hi i have a mx:List with a DataProvider. This data Provider is a ArrayCollection if FotoItems

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 = du开发者_如何学JAVAration;
    }
}

my itemRenderer looks like this:

<?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>

Now when i am scrolling then all images that leave the screen disappear :( When i take a look at the arrayCollection every item's BitmapData is null.

Why is this the case?


I changed Datatype of data in Class FotoItem from Bitmap to BitmapData

in the ItemRenderer i do the following:

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

this works now. No idea why it is not working with bitmaps


I think it might be something with your use of data.data - I believe data is a reserved keyword in Actionscript, and it might be best to name your image property something else, such as data.imageData.

I'm also not sure why you're importing ArrayCollection into your item renderer as you don't appear to be using it in your itemRenderer.

You may also be running into problems with itemRenderer recyling. You may want to override public function set data() and handle setting the individual item properties there instead of relying on binding.

Where are you looking at the arrayCollection to see that the bitmapData is null?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜