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???
Copy link to clipboard
Copied
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