Search code examples
cssapache-flexcolorsflex4states

Flex 4 Item Renderer background colour - states do not work


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>


Solution

  • this works

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