Color de fondo del renderizador de elementos de Flex 4: los estados no funcionan

I have an item renderer with the following states:

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

I am trying to change background color of the items when hovered and selected. I added the following lines to the Item renderer opening tag:

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

Nothing happens when hovered or selected other than default item renderer behaviour (grey color). If I lets say increase the width of the image within:

width.hovered="100"

The image gets resized as expected, how can I achieve the effect I am looking for?

Edit:

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

preguntado el 08 de noviembre de 11 a las 15:11

contentBackgroundColor is a style and width is a property. I wonder if that makes a difference? That said, you should post your full itemRenderer's code. What exactly are you setting the contentBackgroundColor on? -

I added full item renderer code, these styles work perfectly in a component so seems odd, it doesn't work in item renderer. -

3 Respuestas

Put this in the CSS:

s|ItemRenderer:hovered {
 contentBackgroundColor: #ff0018;
}

respondido 21 nov., 11:16

You should use in css :

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

and in mxml : <s:ItemRenderer styleName="myItemRendererStyleName" .... />

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

contestado el 23 de mayo de 12 a las 16:05

esto funciona

<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'"/>

respondido 08 nov., 11:20

That will work indeed, but I will want to move the styles to external css file at some point can you see why the code I added doesn't work? - DominicM

i hope i have understood your question you can define your syle in css in this way: .itemRendererRollover{ backgroundColor:0xff0018 } In your item renderer, inside the state1_enterStateHandler() method, just type bc.setStyle("styleName","itemRendererRollover") Alternatively, it should work also removing the method state1_enterStateHandler() and defining the "styleName.state" property in the mxml declaration of th bc component in this way: <s:BorderContainer styleName.myState = ".itemRendererRollover" styleName.myState2 = ".itemRendererRollover2" ..and so on/> Let me know if works! - marcocb

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.