Here's my take. I might be wrong on some details since I figured this
out through discovery, not documentation, but I think it's generally
correct.

The problem lies in how the list uses renderers. Regardless of how many
items there are in your list, there are only as many renderers created
as there are *visible* rows in the list. As you scroll the list, these
renderers are re-used to display new content. In other words, as you
scroll, each renderer's setData() method is called with a new data
object for it to render.

The solution is to keep the selected state attribute in the data object
which your renderer encapsulates. Bind some visible aspect of the
renderer (background color, eg.) to the selected state attribute in the
data object.
 
Tobias.

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of im_sean_s
Sent: Thursday, April 06, 2006 11:15 AM
To: [email protected]
Subject: [flexcoders] Cell Renderer for List

I was wondering if somone could help me with a cell renderer for a
list.  Basically, I am trying to create a multi-select list where the
user would simply click to select or not select an item.  I have set
the selectable attribute to false for the list and am using a custom
renderer with a mouseDown event.  Then, if the option is selected, I
set the background color of cell renderer.  everything works fine, but
the cell renderer seems to repeat itself, meaning if the list scrolls
and one of the selections are highlighted, then the corresponding row
on the next "page" is also highlighted.  For example, if the list
shows 5 rows and you select row 1, then row 6 will also be
highlighted.  I've listed the code bellow.  If someone could help me
avoid this behavior, it would be much apprecited.

Thank you,
Sean

<mx:HBox        xmlns:mx="http://www.macromedia.com/2003/mxml"; 
        
xmlns:customFields="com.he.view.components.form.customFields.*"
                        mouseDown="onClick()"
                        height="100%" width="100%" hScrollPolicy="off"
vScrollPolicy="off"
verticalAlign="middle" borderStyle="none" backgroundAlpha="0"> 
        
        <mx:Script>
                <![CDATA[ 
                import mx.styles.*;
                import com.he.vo.TopicVO;
                
                var listOwner : Object; // the reference we receive to
the list
                var getCellIndex : Function; // the function we receive
from the list
                var getDataLabel : Function; // the function we receive
from the list
                var selectedItem:TopicVO;
                
                private var selected:Boolean = false;
                private var selectedStyle:CSSStyleDeclaration;
                private var unselectedStyle:CSSStyleDeclaration;
                
                public function setValue(str:String, item:Object):Void {

                        selectedItem = new TopicVO(item);
                        if (item == undefined) { 
                                visible = false; 
                                return; 
                        }else{
                                visible = true;
                        }
                }
                
                private function onClick()
                {
                        var index:Number = getCellIndex().itemIndex;
                        
                        selected = ! selected
                        if (selected)
                        {
        
this.setStyle('backgroundColor','#FFD478');
        
listOwner.dispatchEvent({type:"itemSelected", target:listOwner,
index:index});
                        }
                        else
                        {
        
this.setStyle('backgroundColor','#FFFFFF');
        
listOwner.dispatchEvent({type:"itemUnselected", target:listOwner,
index:index});
                        }
                        
                }
                ]]>
        </mx:Script>
                <mx:Image source="{selectedItem.IMAGE.THUMBURL}"
height="35"
width="35" mouseDown="onClick()" />
                <mx:Label text="{selectedItem.TOPICNAME}" height="35"/>
</mx:HBox> 






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



 






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to