0

我有一个具有以下状态的项目渲染器:

<s:states>
    <s:State name="normal"/>
    <s:State name="hovered"/>
    <s:State name="selected"/>
</s:states>

我试图在悬停和选择时更改项目的背景颜色。我在 Item 渲染器开始标记中添加了以下几行:

contentBackgroundColor.hovered="0xff0018"
contentBackgroundColor.selected="0xffff11"

除了默认项目渲染器行为(灰色)之外,悬停或选择时不会发生任何事情。如果我说增加图像的宽度:

width.hovered="100"

图像按预期调整大小,我怎样才能达到我想要的效果?

编辑:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx"
                xmlns:objects="objects.*"
                creationComplete="itemrenderer1_creationCompleteHandler(event)"
                width="100%" height="100%"
                contentBackgroundColor.hover="0xff0018" focusColor="0xff00ff" contentBackgroundAlpha="0.8"
                dataChange="refreshView()">

    <s:states>
        <s:State name="normal"/>
        <s:State name="hovered"/>
        <s:State name="selected"/>
    </s:states>

    <fx:Declarations>
        <objects:EmbededImages id="embImages"/>
    </fx:Declarations>

    <fx:Script>
        <![CDATA[

            import events.MyEventDispatcher;
            import mx.events.FlexEvent;

            private function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
            {
                //this.parentApplication.MyEventDispatcher.Dispatcher.addEventListener(CastUpdateEvent.UPDATED, refreshView);
                refreshView();
            }

            public function refreshView():void
            {
                var profileImage:File = File.userDirectory.resolvePath("Movie Manager Settings\\profiles\\" + data.@id + ".jpg");
                if(profileImage.exists)
                {
                    personImage.source = profileImage.nativePath as String;
                }
                else
                {
                    personImage.source = embImages.portrait;
                }
            }

        ]]>
    </fx:Script>

    <s:Image id="personImage" top="7" bottom="7" left="7" height="70" width="50"/>
    <s:RichText left="70" height="100%" width="100" text="{data.@name}" textAlign="left" verticalAlign="middle" paddingRight="5"/>
    <s:RichText right="10" height="100%" width="100" text="{data.@character}" textAlign="left" verticalAlign="middle"/>

</s:ItemRenderer>

4

3 回答 3

1

把它放在 CSS 中:

s|ItemRenderer:hovered {
 contentBackgroundColor: #ff0018;
}
于 2011-11-21T12:16:08.883 回答
1

您应该在 css 中使用:

.myItemRendererStyleName:selected #idOflabelInItemRenderer { contentBackgroundColor:#ff0000; }

在 mxml 中: <s:ItemRenderer styleName="myItemRendererStyleName" .... />

<s:Label id="idOflabelInItemRenderer" includeIn="normal,selected" />

于 2012-05-23T12:57:24.703 回答
-1

这行得通

<s:GridItemRenderer currentState="normal" >
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected function state1_enterStateHandler(event:FlexEvent):void{
            bc.setStyle("backgroundColor",0xff0018);
        }

    ]]>
</fx:Script>
<s:states>
    <s:State name="normal"/>
    <s:State enterState="state1_enterStateHandler(event)" name="myState"/>
    <s:State name="selected"/>
</s:states>

<s:BorderContainer id="bc" left="0" right="0" height="{this.height}"/>
<s:Button click="this.currentState = 'prova'"/>

于 2011-11-08T16:37:59.070 回答