flex 4 list ItemRenderer:如何为不同的行设置不同的 itemrenderer? [英] flex 4 list ItemRenderer: how can i have different itemrenderers for different rows?

查看:24
本文介绍了flex 4 list ItemRenderer:如何为不同的行设置不同的 itemrenderer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为游戏创建分数列表.现在我需要的大部分列表都具有相同的 ItemRenderer.但是在列表的特定行中,列出了正在播放的用户,它应该显示不同的信息和不同的背景颜色.我怎样才能做到这一点?

I'm creating a list of scores for a game. now most of the list i need to have the same ItemRenderer. but in one specific row of the list where the user who's playing is listed, it should show different information and with different background color. how can i achieve this ?

我已经尝试通过状态解决问题,我创建了 2 个状态,一个状态称为我的",第二个状态称为其他".

I already tried to resolve the issue with states, i created 2 states, one state called 'mine' and the 2nd state called 'others'.

我遇到的问题是,当用户单击状态更改为 i donno.. clicked 或其他内容的列表行之一时,这就是为什么我认为状态不适合我的原因.

the problems that i got is that when users click on one of the list rows that state changes to i donno.. clicked or something and that's why i assumed that states are not the right action for me.

推荐答案

Flex 4 附带的 spark List 控件允许您根据某些逻辑分配不同的 itemRenderer.

The spark List control that comes with Flex 4 allows you to assign a different itemRenderer depending on some logic.

您可以通过设置 itemRendererFunction 属性来创建自定义项目渲染器函数.

You can create a custom item renderer function by setting the itemRendererFunction property.

    <fx:Script>
    <![CDATA[
        import renderers.*;

        import mx.core.ClassFactory;
        import spark.skins.default.DefaultItemRenderer;

        private function list_itemRendererFunc(item:Object):ClassFactory {
            var cla:Class = DefaultItemRenderer;
            switch (item.type) {
                case "employee":
                    cla = EmployeeItemRenderer;
                    break;
                case "manager":
                    cla = ManagerItemRenderer;
                    break;
                default:
                    break;
            }
            return new ClassFactory(cla);
        }
    ]]>
</fx:Script>

<s:List id="list"
        labelField="name"
        itemRendererFunction="list_itemRendererFunc"
        horizontalCenter="0"
        verticalCenter="0">

这篇关于flex 4 list ItemRenderer:如何为不同的行设置不同的 itemrenderer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆