Search code examples
actionscript-3apache-flex

as3 tilelist with custom itemrender add to selectedIndices


I create a TileList with custom renderer.

    <s:BorderContainer
                   id="bcImage"
                   width="120"
                   height="99%"
                   borderVisible="true"
                   borderStyle="solid"
                   borderColor="#B3B3B3"
                   borderWeight="1"
                   cornerRadius="2"
                   backgroundAlpha=".8"
                   backgroundColor="#F8F8FF"
                   dropShadowVisible="true"
                   >




    <mx:Canvas id="cvsImage" width="100%" click="cvsImage_clickHandler(event)">

        <s:HGroup width="100%" paddingBottom="0" paddingTop="5" >
            <s:CheckBox id="cbImgSelect"/>
            <s:Label x="23" y="3" width="82" fontSize="11" fontWeight="normal" text="{data.imDate}"
                     textAlign="right" color="#000000"/>    
        </s:HGroup>  


        <mx:Image id="iconCanvas" x="10" y="20" width="99" height="99" horizontalAlign="center"
                  maintainAspectRatio="true" scaleContent="true"
                  verticalAlign="middle" mouseDown="iconCanvas_mouseDownHandler(event)"
                  >

        </mx:Image>
    </mx:Canvas>

    <s:BorderContainer width="100%" y="124" height="25" bottom="1" left="3" right="3" 
                       backgroundColor="#FFFFFF" id="bcTitre" borderAlpha="0" >
        <s:VGroup width="100%" y="124" height="25" bottom="0" left="0" right="0"
                  paddingBottom="0" paddingTop="0" gap="0" click="iconCanvasLabel_mouseUp(event)">
            <s:Label text="{data.imType}" height="50%" fontSize="10" paddingBottom="1" id="lType"
                     fontWeight="normal" width="99%" textAlign="center" toolTip="{data.imType}"/>
            <s:Label text="{data.imStade}" fontSize="10" textAlign="center" paddingTop="1"
                     fontWeight="normal" width="99%" id="lStade" toolTip="{data.imStade}"/> 

        </s:VGroup>
    </s:BorderContainer>


</s:BorderContainer>

My TileList has allowMultipleSelection enable.

I'd to check CheckBox when item is selected by click or by selection (continus or not) and if CheckBox.selected=true I'd like to show color selection around selected item.

Could you help me to do that ?

Best regards


Solution

  • It seems that you're trying to resolve the issue from opposite side, which is wrong I suppose yo can consider following way:

    • set mouseEnabled to false for checkBox so that all the list item triggers click
    • alter default selection behaviour by intercepting changing event and doing something like

      protected function lst_changingHandler(evt:IndexChangeEvent):void {
              evt.preventDefault();
              var ids:Vector.<int> = (evt.currentTarget as List).selectedIndices;
              (evt.currentTarget as List).selectedIndices = ids.concat(new <int>[evt.newIndex]);
      
    • bind checkBox selected state to the renderer selected one