• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

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

New Here ,
May 05, 2010 May 05, 2010

Copy link to clipboard

Copied

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

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2010 May 25, 2010

Copy link to clipboard

Copied

LATEST

Hi,

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"
                          xmlns:s="library://ns.adobe.com/flex/spark"
                          xmlns:mx="library://ns.adobe.com/flex/mx"
                          focusEnabled="true" >
    <fx:Script>
        <![CDATA[
            var clicked:Boolean=true;
            protected function clickHandler(event:MouseEvent):void
            {
                    clicked?labelRender.setStyle("color","0x00FF00"):labelRender.setStyle("color","0xFF0000");
                    clicked=!clicked;
                }

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

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

Nishad

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines