自定义IconItemRender与列表一起使用滞后

时间:2013-01-05 12:43:29

标签: flash flex mobile builder

我在List中使用了自定义IconItemRender。当我将图像嵌入到列表中并在设备上进行测试时,列表滚动的动画并不酷,它是滞后的。如果没有嵌入图像,列表滚动动画就可以了。

为什么列出滞后的任何建议?

以下是代码:

package components
{
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;

import mx.core.DPIClassification;

import spark.components.IconItemRenderer;
import spark.components.Image;
import spark.components.LabelItemRenderer;
import spark.components.supportClasses.StyleableTextField;

public class Shops extends IconItemRenderer
{   
    private static var bkgColor:Boolean;

    protected var storeName:StyleableTextField;
    protected var floor:StyleableTextField;
    protected var _data:Object;
    protected var floorTextSize:int;
    protected var promotions:Image;
    protected var promotionHolder:Sprite;

    [Embed(source="assets/map_list320.png")]
    public static const mapList:Class;

    public function Shops()
    {
        //TODO: implement function
        super();

        switch (applicationDPI) {

            case DPIClassification.DPI_160:

                floorTextSize = 11;
                break;

            case DPIClassification.DPI_240:

                floorTextSize = 20;
                break;

            case DPIClassification.DPI_320:

                floorTextSize = 16;
                break;
        }
    }

    /**
     * @private
     *
     * Override this setter to respond to data changes
     */
    override public function set data(value:Object):void
    {
        _data = value;

        if (storeName) storeName.text = _data.title;
        if (floor) floor.text = 'етаж: ' + _data.floor;

        // the data has changed.  push these changes down in to the 
        // subcomponents here           
    } 

    /**
     * @private
     * 
     * Override this method to create children for your item renderer 
     */ 
    override protected function createChildren():void
    {   
        // promotion if exist
        promotionHolder = new Sprite();
        addChild(promotionHolder);

        // store name
        storeName = new StyleableTextField();
        storeName.defaultTextFormat = new TextFormat( getStyle( "fontFamily" ), getStyle( "fontSize" ), getStyle('color') );
        addChild( storeName );

        // floor
        floor = new StyleableTextField();
        floor.defaultTextFormat = new TextFormat(getStyle( "fontFamily" ), floorTextSize, 0x999999);
        addChild(floor);

        // map


        var img:Image = new Image();
        img.source = mapList;
        img.cacheAsBitmap = true;
        img.width = 64;
        img.height = 64;
        addChild(img);
    }

    /**
     * @private
     * 
     * Override this method to change how the item renderer 
     * sizes itself. For performance reasons, do not call 
     * super.measure() unless you need to.
     */ 
    override protected function measure():void
    {

    }

    /**
     * @private
     * 
     * Override this method to change how the background is drawn for 
     * item renderer.  For performance reasons, do not call 
     * super.drawBackground() if you do not need to.
     */
    override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
    {
        graphics.beginFill(bkgColor ? 0xFFFFFF : 0xf0f4fb, 1);
        graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);

        bkgColor = !bkgColor;
    }

    /**
     * @private
     *  
     * Override this method to change how the background is drawn for this 
     * item renderer. For performance reasons, do not call 
     * super.layoutContents() if you do not need to.
     */
    override protected function layoutContents(unscaledWidth:Number, 
                                               unscaledHeight:Number):void
    {
        super.layoutContents(unscaledWidth, unscaledHeight);
        // layout all the subcomponents here            
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {

        // position the field 
        storeName.x = unscaledWidth / 10;
        storeName.y = (unscaledHeight - (storeName.textHeight + floor.textHeight + (unscaledHeight/10))) / 2;

        floor.x = unscaledWidth / 10;
        floor.y = storeName.y + storeName.textHeight + (unscaledHeight/10);


        // we draw a separator line between each item
        var lineY:int = unscaledHeight -1;
        graphics.clear();
        graphics.lineStyle(1, 0xd9d9d9);
        graphics.moveTo( 0, lineY );
        graphics.lineTo( unscaledWidth, lineY );

        drawBackground(unscaledWidth, unscaledHeight);
    }
}

}

0 个答案:

没有答案