Problem: missing mx.core.IFactory
When trying to dynamically add an itemRenderer to a component in Flex you cannot specify it by string path as in MXML mode. Doing so you get a TypeError similar to the following:
Type Coercion failed: cannot convert “path.to.YourItemRenderer” to mx.core.IFactory
Solution: use ClassFactory()
Working in AS3 with dynamic objects, not MXML references, you need to instantiate the itemRenderer with a ClassFactory. This causes the itemRenderer to implement the required mx.core.IFactory interface.
Example
import mx.core.ClassFactory; import path.to.YourItemRenderer; var col:DataGridColumn = new DataGridColumn(); col.itemRenderer = new ClassFactory(YourItemRenderer);
Filed under: ActionScript 3, Flex, How to, ActionScript3, AS3, ClassFactory, Component, DataGridColumn, Flex, IFactory, itemRenderer, mx.core.IFactory
Just what I needed – was casting to IFactory as auto-suggested by FDT, which did not help. thank you for finding and posting this!
Good post. Thanks, saved me some time.