flex prevent selection state on spark list

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

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.

链接地址: http://www.djcxy.com/p/34624.html

上一篇: 将参数发送到自定义ItemRenderer?

下一篇: 弯曲防止火花列表上的选择状态