Flex ComboBox items go out of alignment
I have a combobox that uses a custom itemrenderer to display an image. when scrolling up and down the list the images randomly go out of alignment. How do I stop this?
public class PinRenderer extends UIComponent implements IDataRenderer, IListItemRenderer
{
private var currentPin:DisplayObject;
private var _data:Object;
public function get data():Object
{
return _data;
}
public function set data( value:Object ):void
{
_data = value;
invalidateDisplayList();
}
override protected function measure():void
{
super.measure();
measuredHeight = measuredMinHeight = 19;
measuredWidth = measuredMinWidth = 19;
}
private var pins:Dictionary = new Dictionary();
override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
{
super.updateDisplayList( unscaledWidth, unscaledHeight );
var note:PerformanceNote;
if ( data != null && ( data is PerformanceNote || data is Number ) )
{
var color:uint;
if ( data is PerformanceNote )
{
color = PerformanceNote( data ).note_pin_color;
}
else if ( data is Number )
{
color = Number( data );
}
var pinClass:Class = Constants.PIN_IMAGES[ color ];
var pin:DisplayObject = pins[ pinClass ];
if ( !pin )
{
pin = new pinClass();
pin.x = ( unscaledWidth - pin.width ) / 2;
pin.y = ( unscaledHeight - pin.height ) / 2;
pins[ pinClass ] = pin;
}开发者_StackOverflow中文版
if ( currentPin )
{
removeChild( currentPin );
}
addChild( pin );
currentPin = pin;
}
}
}
instead of doing most of the logic in the updateDisplayList, I moved it to commitProperties, but left setting pin.x and pin.y in the updateDisplayList. This fixed the problem I was having.
精彩评论