Objective: I would like to pass Skins to an itemRenderer (which is a Button) of a List, and be able to skin every button in that List.
This is what I have:
List:
<s:List itemRenderer="renderers.ItemRenderer" dataProvider="{collectionWorkspace}" />
ArrayCollection:
<s:ArrayCollection id="collectionWorkspace">
<comp:Layout1 />
<comp:Layout2 />
<comp:Layout3 />
<comp:Layout4 />
<comp:Layout5 />
</s:ArrayCollection>
The Layouts are Skin classes with HostComponent Button.
ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:states>
<s:State name="normal" />
</s:states>
<s:Button skinClass="{data}"/>
</s:ItemRenderer>
I get an error (fixed for clarification):
Error: Skin for Application….Button1 cannot be found.
You are handing the
skinClassproperty an instance of the skin class, not the actual class (which the button needs to create its own instance of the skin class).If you can, the best thing to do would be to make
collectionWorkspacebe an array of Class objects, not of instances.If you can’t do that, you should be able to pull out the class of the instance and pass it to the
skinClass.EDIT:
The binding by default won’t work because
datastarts off asnullbefore it gets initialized with the class. If you give itnull, you will get the exception. To fix it, you will need to return the default for the time betweennulland value:I tried doing this with an
ArrayCollectionusing some button skins. It worked.