0 Replies Latest reply on Jul 30, 2009 9:53 AM by David_F57

    Spark list Selectedindex all -1

    David_F57 Level 5

             I have a custom renderer for list which enables drag for each item, it seems the mousedown event overrides the default behavior which means the item index always remains at -1, either this is the continuation of an earlier issue with render states or i'm doing something wrong (i'm thinking the later).

       

      Any help would be appreciated.

      <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/halo" width="80" height="70">
           
           <s:states>
                <s:State name="normal"/>            
                <s:State name="hovered"/>
                <s:State name="selected"/>
                <s:State name="normalAndShowsCaret"/>
                <s:State name="hoveredAndShowsCaret"/>
                <s:State name="selectedAndShowsCaret"/>
           </s:states>
           
           <fx:Script>
                <![CDATA[
                     
                     import mx.managers.DragManager;
                     import mx.core.DragSource;
                     import mx.events.DragEvent;
                     
                     [Bindable("dataChanged")]
                     override public function set data(value:Object):void
                     {
                          img.source=value;
                     }
      
                     protected function img_mouseDownHandler(event:MouseEvent):void
                     {
                          var target:Image = Image(event.currentTarget);
                          var sourceObject:Object = new Object();
                          sourceObject.width = img.content.width;
                          sourceObject.height = img.content.height;
                          sourceObject.img = img.source;
                          var dragSource:DragSource = new DragSource();
                          dragSource.addData( sourceObject, "image" );
                          mx.managers.DragManager.doDrag( target, dragSource, event, null , -0, -0, 0.40, true );
                     }
      
                ]]>
           </fx:Script>
           
           <s:Rect left="0" right="0" top="0" bottom="0">
                <s:stroke.normalAndShowsCaret>
                     <s:SolidColorStroke 
                          color="{selectionColor}" 
                          weight="1"/>
                </s:stroke.normalAndShowsCaret>
                <s:stroke.hoveredAndShowsCaret>
                     <s:SolidColorStroke 
                          color="{selectionColor}" 
                          weight="1"/>
                </s:stroke.hoveredAndShowsCaret>
                <s:stroke.selectedAndShowsCaret>
                     <s:SolidColorStroke 
                          color="{selectionColor}" 
                          weight="1"/>
                </s:stroke.selectedAndShowsCaret>
                <s:fill>
                     <s:SolidColor 
                          color.normal="{contentBackgroundColor}"
                          color.normalAndShowsCaret="{contentBackgroundColor}" 
                          color.hovered="{rollOverColor}"
                          color.hoveredAndShowsCaret="{rollOverColor}"
                          color.selected="{selectionColor}"
                          color.selectedAndShowsCaret="{selectionColor}"
                          />
                </s:fill>
           </s:Rect>
           
           <s:Group id="contentGroup" verticalCenter="2" left="0" right="2" top="2" bottom="2">
                <mx:Image id="img" top="0" left="0" bottom="0" right="0" 
                            verticalAlign="middle" horizontalAlign="center"
                            mouseDown="img_mouseDownHandler(event)"/>
           </s:Group>
           
      </s:ItemRenderer>