1 Reply Latest reply on May 25, 2010 4:39 AM by MNishad

    how do i set spark list selected item's color??

    cyber0897 Level 1

      hey guys... so got a little problem... i have a spark list which gets populated from a array collection that looks likda like this

      [0] = "name1"

      [1] = "name 2"

      [2] = "name 3"




      when i click on say "name 1" i  need the color of "name 1" to change to say red...


      and when i click on another item i need that color to stay... red on "name 1"...


      oh and... i need to do the color change in actionscript rather than the mxml file...


      any ideas???

        • 1. Re: how do i set spark list selected item's color??



          I'm not sure if this is exactly what you are looking for. What I did was created an itemRender for the list and assigned it like so


          <s:List dataProvider="{ listDataProvider}" itemRenderer="listItemRenderer"/>


          And the listItemRenderer will look some

          //Code Begins

          <?xml version="1.0" encoding="utf-8"?>
          <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                    focusEnabled="true" >
                      var clicked:Boolean=true;
                      protected function clickHandler(event:MouseEvent):void
                              clicked?labelRender.setStyle("color","0x00FF00"):labelRender.setStyle("color","0xFF0000") ;


              <s:Label  id="labelRender" text="{data}" color="0xFF0000" click="clickHandler(event)"/>

          //Code Ends

          In the above example the colour toggles on each click. So, you can apply anything. assume you have a property called color in your array collection, you can access it as data.color and then set the text to that color when it is clicked. I hope this helps. Do write back if you have any issues.