Flex项呈示器 - 单击时更改alpha

时间:2012-06-06 13:43:00

标签: flex flex4 flex-mobile

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

CODE:

<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>

1 个答案:

答案 0 :(得分:2)

您可以使用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值来完成同样的工作。