views:

25

answers:

1

I have an item renderer for a grid that has a fairly basic updateDisplayList function:

override protected function updateDisplayList( w : Number, h : Number ) : void
{
    super.updateDisplayList( w, h );

    var labelWidth : Number = Math.min( _labelDisplay.measuredWidth, w );
    var labelHeight : Number = Math.min( _labelDisplay.measuredHeight, h );

    _labelDisplay.setActualSize( labelWidth, labelHeight );

    var labelX : Number = ( w - _labelDisplay.width ) / 2;
    var labelY : Number = ( h - _labelDisplay.height ) / 2;

    _labelDisplay.move( labelX, labelY );

    //this is just for debugging
    graphics.clear();
    graphics.beginFill( 0xFF0000, 0.5 );
    graphics.drawRect( labelX, labelY, labelWidth, labelHeight );
    graphics.endFill();
}

where _labelDisplay is a spark label. When I scroll the grid (this is a cuatom grid, not mx:Grid or AndvancedDataGrid) when new rows appear at the bottom of the grid updateDisplayList is called and the code to re-draw the background and move / resize the label executes.

The problem is that these chanegs are not reflected in the view. The text is mis-aligned as a label that used to display a large string now displays a short string so the measuredWidth has changed.

The next time I scroll the renders update to look like they should - but updateDisplayList is NOT called here (on the renderes). All that happens is that the renderers are re-positioned in the grid. Both the background and the label are displayed incorrectly initially so it's not just the label mis-behaving.

Anyone got any idea why this is happening?

Thanks

A: 

Just a guess, but does this make any difference?

override protected function updateDisplayList( w : Number, h : Number ) : void
{
    var labelWidth : Number = Math.min( _labelDisplay.measuredWidth, w );
    var labelHeight : Number = Math.min( _labelDisplay.measuredHeight, h );

    _labelDisplay.setActualSize( labelWidth, labelHeight );

    var labelX : Number = ( w - _labelDisplay.width ) / 2;
    var labelY : Number = ( h - _labelDisplay.height ) / 2;

    _labelDisplay.move( labelX, labelY );

   super.updateDisplayList( w, h ); // Call updateDisplayList after moving / resizing _labelDisplay
}
Marty Pitt