如何创建一个自定义单元格渲染器平铺列表中闪光平铺、自定义、创建一个、单元格

2023-09-08 13:11:41 作者:嘴硬的女生欠吻i

我需要实现我的一个项目一个自定义的格渲染器,我已经做了一些谷歌搜索,但没有找到我所需要的。

I need to implement a custom cell renderer in a project of mine, I have done some search on google but couldn't find what I need.

我需要每个平铺列表细胞来显示2个图标与夫妇的标签。我需要一个很好的例子,来启动它。

I need each cell in the tile list to display 2 icons with couple of labels. I need a good example to start it.

如果可能,我需要一种方法来设计模板作为影片剪辑,并把它传递给TileList的渲染单元。

If possible I need a way to design the template as a MovieClip and pass it to the tilelist for rendering the cells.

推荐答案

要建立你需要从可用扩展一个类所选择的自定义单元格渲染器 listClasses 。 的ImageCell 看起来像一个良好的开端为您的项目。

To build a custom cell renderer you need extend a class of choice from the available listClasses. ImageCell looks like a good start for your project.

您会:

扩展列表类 在添加自己的位(标签/文本字段,等等。) 在改写保护功能,以调整新细胞,以您的需求(一个例子是drawLayout方法,在那里你会需要整齐地放置您的项目)。

下面是一个非常简单的例子:

Here's a very basic example:

package
{
    import fl.controls.listClasses.ICellRenderer;
    import fl.controls.listClasses.ImageCell;
    import fl.controls.TileList;
    import fl.data.DataProvider;
    import fl.managers.StyleManager;
    import flash.events.EventDispatcher;
    import flash.events.*;
    import fl.containers.UILoader;

    public class CustomImageCell extends ImageCell implements ICellRenderer
    {  

        public function CustomImageCell() 
        {
            super();

            //do other stuff here

            loader.scaleContent = false;
            loader.addEventListener(IOErrorEvent.IO_ERROR, handleErrorEvent, false, 0, true);

            useHandCursor = true;
        }

        override protected function drawLayout():void
        {
            var imagePadding:Number = getStyleValue("imagePadding") as Number;
            loader.move(11, 5);

            var w:Number = width-(imagePadding*2);
            var h:Number = height-imagePadding*2;
            if (loader.width != w && loader.height != h)
            {
                loader.setSize(w,h);
            }
            loader.drawNow(); // Force validation!

        }
        override protected function handleErrorEvent(event:IOErrorEvent):void {
            trace('ioError: ' + event);
            //dispatchEvent(event);
        }
    }
}

一个pretty的很好的例子,你需要的是在这个交。 该自定义单元格提供了:

A pretty good example for what you need is on this post. The custom cell provided there:

支持自定义背景(通过设置细胞皮肤) 使用标签文本字段。

心连心