With Flex 4.10 and a spark List using IconItemRenderer -
is it please possible to display decorator images only for some List items?
I have a List representing a weekly Top-rating of players and wonder how to display the medal for winners only:
<fx:Declarations>
<s:MultiDPIBitmapSource id="MEDAL"
source160dpi="@Embed('assets/icons/160/medal-gold.png')"
source240dpi="@Embed('assets/icons/240/medal-gold.png')"
source320dpi="@Embed('assets/icons/320/medal-gold.png')"
source480dpi="@Embed('assets/icons/480/medal-gold.png')" />
<s:ArrayCollection id="_ac" />
</fx:Declarations>
<s:List id="_list"
width="100%"
height="100%"
dataProvider="{_ac}"
change="handleChange(event)">
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer
iconField="avatar"
messageField="city"
decorator="{outerDocument.MEDAL}"
iconFunction="{outerDocument.iconFunc}"
labelFunction="{outerDocument.labelFunc}" />
</fx:Component>
</s:itemRenderer>
</s:List>
The short answer is to set the decorator to null in your data change function.
Longer answer:
<s:IconItemRenderer
iconField="avatar"
messageField="city"
decorator="{outerDocument.MEDAL}"
iconFunction="{outerDocument.iconFunc}"
labelFunction="{outerDocument.labelFunc}"
dataChange="onDataChange(event)" >
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
public var statManager :StatManager = StatManager.instance;
protected function onDataChange(event:FlexEvent):void
{
if(SomeConditionThatDeterminesThatDecoratorShouldBeDisplayed){
this.decorator = outerDocument.MEDAL;
} else {
this.decorator = null;
}
}
]]>
</fx:Script>
</s:IconItemRenderer>
I use this same approach in my mobile game.