views:

219

answers:

2

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 = duration;
    }
}

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?

A: 

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?

quoo
i tried to change data.data into something else but this doesn't work eighter.i am not using an arrayCollection in my renderer. The data provider is an arrayCollection.i also think it has to do with the recycling. but it shouldn't alter the data in the arrayCollection, should it?i am looking at the data in my debug view
Dominik
A: 

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

Dominik
If the value you were originally instantiating data with was of type BitmapData, that would explain why a Bitmap value was coming back as null. You can't just assign BitmapData to a Bitmap and have it automatically convert.
quoo