【问题标题】:Flex item renderer - change alpha when clickedFlex 项目渲染器 - 单击时更改 alpha
【发布时间】:2012-06-06 22:47:38
【问题描述】:

我想在单击列表项时更改 Rect 的 alpha,但我无法解决这个问题。而且我不知道究竟是如何做到这一点的,因为我在项目渲染器内的 Rectangle 上这样做,有什么建议吗?

代码:

<s:List id="list" labelField="name" dataProvider="{items}" top="20" bottom="20" left="20" right="20" 
                contentBackgroundAlpha="0"
                change="list_changeHandler(event)">
            <s:itemRenderer>
                <fx:Component>
                    <s:ItemRenderer width="100%" height="200" autoDrawBackground="false" contentBackgroundAlpha="0">

                        <s:Group width="100%" height="100%">
                            <s:Rect id="rect" left="0" right="0" top="0" bottom="0" alpha="0.3">
                                <s:fill>
                                    <s:SolidColor color="#FFFFFF" 
                                                   />
                                </s:fill>
                            </s:Rect>
                            <s:Image source="{data.icon}" top="30" horizontalCenter="0"/>
                            <s:Label text="{data.name}" top="100" horizontalCenter="0" color="#101010" fontWeight="bold" fontSize="16"/>
                            <s:Label text="{data.line1}" top="130" horizontalCenter="0" color="#343434" fontSize="14"/>
                            <s:Label text="{data.line2}" top="150" horizontalCenter="0" color="#343434" fontSize="14"/>
                        </s:Group>
                    </s:ItemRenderer>
                </fx:Component>
            </s:itemRenderer>
            <s:layout>
                <s:TileLayout requestedColumnCount="3" requestedColumnCount.landscape="4" columnAlign="justifyUsingWidth"/>
            </s:layout>
        </s:List>

【问题讨论】:

    标签: apache-flex flex4 flex-mobile


    【解决方案1】:

    您可以为此使用 ItemRenderer 的状态。将这些状态添加到您的 ItemRenderer:

    <s:states>
        <s:State name="normal" />
        <s:State name="hovered" />
        <s:State name="selected" />
    </s:states>
    
    <s:Rect left="0" right="0" top="0" bottom="0">
        <s:fill>
            <s:SolidColor color.normal="0x0000ff" 
                          color.hovered="0x00ff00" 
                          color.selected="0xff0000" />
        </s:fill>
    </s:Rect>
    

    使用此代码,您的渲染器默认为蓝色;当你将鼠标悬停在它上面时它会变成绿色;选择它时为红色。当然,alpha 值也可以做到这一点。

    【讨论】:

    • +1 来自我;我不知道 ItemRenderer 类有预定义的状态。
    • @www.Flextras.com 看看ItemRenderer#getCurrentRendererState() 代码
    • 谢谢!对我理解状态的使用非常有帮助的例子!..(我不经常使用它们,但我想我会从现在开始)再次感谢!
    • @lbstr “新”状态机制是 Spark 最强大的功能之一。我一直在使用它们。你必须意识到这个例子是一个特例,因为状态和它们的触发器已经在 ItemRenderer 类中预定义(例如,用户用鼠标悬停在渲染器上 > 切换到“悬停”状态)。在大多数情况下,您必须自己设置这些触发器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 2021-10-28
    • 2012-01-03
    • 2010-11-06
    • 1970-01-01
    相关资源
    最近更新 更多