Flex ComboBox项目不一致

时间:2010-03-29 23:42:41

标签: flex image combobox alignment

我有一个组合框,它使用自定义itemrenderer来显示图像。当在列表中上下滚动时,图像随机地不对齐。我该如何阻止它?

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;
            }
            if ( currentPin )
            {
                removeChild( currentPin );
            }

            addChild( pin );
            currentPin = pin;
        }
    }

}

1 个答案:

答案 0 :(得分:0)

而不是执行updateDisplayList中的大部分逻辑,我将其移动到commitProperties,但在updateDisplayList中设置了pin.x和pin.y。这解决了我遇到的问题。