0

I have an ItemRenderer in which the selected state should be disabled (I'm using the renderer states and I don't have a selected state). The problem is that the list (spark) resets the item renderer state upon click even though I don't have a "selected" state.

I want to fully prevent this behavior but I don't know how. My renderer has autoDrawBackground set to false but it has to be enabled (although enabled=false fixes this issue) Also, the renderer has several children including a list of its own. Setting mouseEnabled="false" on the renderer fixes the renderer itself but not its children, and I need some of the children to be mouse enabled.

Edit:

Following is an excerpt from my item renderer:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:mx="library://ns.adobe.com/flex/mx" 
                xmlns:s="library://ns.adobe.com/flex/spark"
                width="100%" autoDrawBackground="false">

    <s:states>
        <s:State name="normal" />
        <s:State name="suitable" />
        <s:State name="mine" />
        <s:State name="deleted" />
    </s:states>

    <s:Rect id="rect" top="0" right="0" bottom="0" left="0">
        <s:fill>
            <s:SolidColor id="background"
                          alpha=".8" alpha.deleted=".4"
                          color="0xff0000" color.suitable="0x00ff00" color.mine="0x0000ff" />
        </s:fill>
    </s:Rect>

    <s:Label id="name" left="4" top="4" right="40" />

    <s:List id="myList" left="4" top="40" right="4"
            contentBackgroundAlpha="0" borderVisible="false" horizontalScrollPolicy="off">
        <s:layout>
            <s:VerticalLayout gap="3" paddingBottom="4" requestedMinRowCount="2" />
        </s:layout>
    </s:List>
</s:ItemRenderer>

Second Edit:

I had the same problem with the mouse hover state but that seems to have a workaround:

override protected function set hovered(value:Boolean) : void
{
    // do nothing (prevent current state from changing to "hovered" state)
}
Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169
Ofir
  • 1,565
  • 3
  • 23
  • 41
  • can you post the code for your renderer –  Oct 17 '13 at 10:01
  • possible duplicate of [How to prevent an item from be selected in a List](http://stackoverflow.com/questions/12254718/how-to-prevent-an-item-from-be-selected-in-a-list) – splash Oct 17 '13 at 10:54
  • @splash, I've seen this post but adding the "changing" event didn't solve my issue – Ofir Oct 17 '13 at 11:17
  • @Lee, I've updated the question with the relevant code. – Ofir Oct 17 '13 at 16:26

1 Answers1

0

I'm unclear if you want to prevent an item from being selected; or just prevent the visual properties that go along with an item being selected.

To handle the visual aspects; I'd try to override the getCurrentRendererState() method. Something like this:

override protected function getCurrentRendererState():String{
  if (selected && hasState("selected"))){
    return "normal"; // or whatever state you want it to be
  }
  if (selected && down && hasState("downAndSelected")){
     return "normal"; // or whatever state you want it to be
  }        

  super.getCurrentRendererState()

}

In theory, this should prevent your renderer from ever going into a selected state.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Thanks @Reboog, I've seen this theory also, but it doesn't work. Moreover, I would have expected hasState("selected") to return false but that's another story ... – Ofir Oct 17 '13 at 13:35
  • the selected state still exists in your renderer. your renderer extends ItemRenderer so you inherit its properties (including states) resulting in hasState("selected")==true –  Oct 17 '13 at 16:40
  • True but shouldn't `states=["foo", "bar"]` override whatever states were previously defined? Isn't it the same as the mxml code? – Ofir Oct 17 '13 at 17:45
  • @LeeBurrows I just checked all files in the hierarchy chain. I can't see where the states array is set tin the ItemRenderer class. My intent w/ the above code was to say "if the state is X' return Y"; which I thought would change the visual display; but perhaps I'm missing an important aspect [I did write that in a browser w/o tested code] – JeffryHouser Oct 17 '13 at 17:58
  • @Reboog sorry for confusion; my comment was aimed at Ofir's first response to your answer (which looks sound to me). –  Oct 17 '13 at 18:20
  • @Ofir. please clarify whether you wish to stop the item being selected, or just to stop the appearance changing. –  Oct 17 '13 at 18:21
  • @LeeBurrows, my aim is visual, although I do not need the selection either – Ofir Oct 17 '13 at 20:36