Hi Guys,

I started going down the same root as Philippe, but I think using the
isSelected and setPropertiesAt might be a bit cleaner.  Here's the
code below.  You can also see it in action here:

http://flexdemos.prismix.com/samples/blog_examples/listIcons.mxml?versionChecked=true

The only downside I see is that you need to loop through all items in the list.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
width="250" height="425">

        <mx:Script>
        <![CDATA[
                [Embed(source="assets/icons/small/add.png")]
                var activeIcon:String;
                [Embed(source="assets/icons/small/delete.png")]
                var inActiveIcon:String;
                
                function toggleIcons(event)
                {
                        var listControl = event.target;
                        var activeObject = {icon: activeIcon};
                        var inActiveObject = {icon: inActiveIcon};

                        // Reset Icons
                        for (var i in listControl.dataProvider)
                        {
                                if (listControl.isSelected(i))
                                        listControl.setPropertiesAt(i, 
activeObject);
                                else
                                        listControl.setPropertiesAt(i, 
inActiveObject);
                        }
                }
        ]]>
        </mx:Script>

        <mx:Text text="Single Selection" />

        <mx:List id="theList" width="200" change="toggleIcons(event)"
creationComplete="toggleIcons(event)">
                <mx:dataProvider>
                        <mx:Array>
                                <mx:Object label="Item 1" icon="{inActiveIcon}" 
/>
                                <mx:Object label="Item 2" icon="{inActiveIcon}" 
/>
                                <mx:Object label="Item 3" icon="{inActiveIcon}" 
/>
                                <mx:Object label="Item 4" icon="{inActiveIcon}" 
/>
                        </mx:Array>
                </mx:dataProvider>
        </mx:List>

        <mx:Text text="Multiple Selection" />

        <mx:List id="theOtherList" width="200" change="toggleIcons(event)"
multipleSelection="true" creationComplete="toggleIcons(event)">
                <mx:dataProvider>
                        <mx:Array>
                                <mx:Object label="Item 1" icon="{inActiveIcon}" 
/>
                                <mx:Object label="Item 2" icon="{inActiveIcon}" 
/>
                                <mx:Object label="Item 3" icon="{inActiveIcon}" 
/>
                                <mx:Object label="Item 4" icon="{inActiveIcon}" 
/>
                        </mx:Array>
                </mx:dataProvider>
        </mx:List>

</mx:Application>

Cheers

Niklas


On 10/08/05, Philippe Maegerman <[EMAIL PROTECTED]> wrote:
>  
> I have something working, there might be a simplier solution but that's all
> I have (see attachment) ;)) 
>   
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application
> xmlns:mx="http://www.macromedia.com/2003/mxml";>
> <mx:Script>
>  [Embed(source="icon.gif")]
>  var myIcon:String; 
>  //reference to list selectedIndex
>  var currentItem;
>  function setSelectedIcon(event){
>   var myList = event.target;
>   if(currentItem!=undefined){
>    //remove the icon on the previous selected item in the list dataProvider
>    myList.dataProvider[currentItem].icon = null;
>    }
>    //set currentItem to new index
>    currentItem = myList.selectedIndex;
>    //update the icon property for the current item in the list dataProvider
>    myList.dataProvider[myList.selectedIndex].icon = myIcon;
>    //trick to redraw the list and reselect index
>    myList.dataProvider = myList.dataProvider;
>    myList.selectedIndex = currentItem;
>    
>  }
> </mx:Script>
> <mx:Model id="myModel">
>  <item icon="" label="item1"/>
>  <item icon="" label="item2"/>
> </mx:Model>
> <mx:List dataProvider="{myModel.item}"
> change="setSelectedIcon(event)"/>
> </mx:Application> 
>   
> Philippe Maegerman 
> Web developer 
>  ________________________________
>  From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Brooks Andrus
> Sent: mercredi 10 août 2005 10:34
> To: [email protected]
> Subject: RE: [flexcoders] Re: selectedItem in a list shows an icon
> 
>  
>  
>  
> 
> Does the list component in Flex not have setPropertiesAt() ?  This method of
> the list takes two arguments: 
>  
> 
> 1)       the index of the row in the list you want to modify (listen for a
> change event and then check the selectedIndex  property of the list). 
> 
> 2)       a style object which allows 2 properties of the row in question to
> be set-the backgroundColor (hex value) and an icon (in Flash the icon
> properties value would be equivalent to the linkage id of a MovieClip in the
> library you wished to use as an icon). 
> 
>   
> 
> I hope this helps-I'm a Flash guy who lurks on the flexcoders list in a lame
> attempt to keep abreast of the technology. 
> 
>   
> 
> Regards, 
> 
>   
> 
> Brooks 
> 
>   
>  ________________________________
>  
> 
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Ghislain Simard
> Sent: Tuesday, August 09, 2005 10:06 PM
> To: [email protected]
> Subject: [flexcoders] Re: selectedItem in a list shows an icon 
> 
>   
> 
> Is there an example you can show me...I'm not quite sure to 
> understand what you proposed.
> Thanks
> 
> --- In [email protected], "JesterXL" <[EMAIL PROTECTED]> wrote:
> > Use a custom cellRenderer that shows an icon when the 3rd 
> parameter to the 
> > setValue function is "selected".
> > 
> > ----- Original Message ----- 
> > From: "Ghislain Simard" <[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Sent: Tuesday, August 09, 2005 11:03 PM
> > Subject: [flexcoders] selectedItem in a list shows an icon
> > 
> > 
> > HI,
> > How can we get a list and once an item is selected we see an icon
> > appearing beside that selectedItem?
> > 
> > thanks
> > 
> > 
> > 
> > 
> > 
> > --
> > 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 
>  
>  
>  Visit your group "flexcoders" on the web.
>   
>  To unsubscribe from this group, send an email to:
>  [EMAIL PROTECTED]
>   
>  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 
>  
>  ________________________________
>  
> 
> ------------------------------------------------------------------
> **STATEMENT OF CONFIDENTIALITY** 
> 
> This e-mail and any attached files are confidential and intended solely for
> the use of the individual to whom it is addressed. If you have received this
> email in error please send it back to the person that sent it to you. Any
> views or opinions presented are solely those of author and do not
> necessarily represent those the Emakina Company. Unauthorized publication,
> use, dissemination, forwarding, printing or copying of this email and its
> associated attachments is strictly prohibited. 
> 
> We also inform you that we have checked that this message does not contain
> any virus but we decline any responsability in case of any damage caused by
> an a non detected virus.
> ------------------------------------------------------------------
> 


-- 
Niklas Richardson
Prismix Ltd

Flex and ColdFusion Experts!


------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a 
href="http://us.ard.yahoo.com/SIG=12hrmmavk/M=362329.6886308.7839368.1510227/D=groups/S=1705007207:TM/Y=YAHOO/EXP=1123677853/A=2894321/R=0/SIG=11dvsfulr/*http://youthnoise.com/page.php?page_id=1992
">Fair play? Video games influencing politics. Click and talk back!</a>.</font>
--------------------------------------------------------------------~-> 

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