Bitesize Bugs

Dinamically add an itemRenderer in Flex

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 “” 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.


import mx.core.ClassFactory;

var col:DataGridColumn = new DataGridColumn();
col.itemRenderer = new ClassFactory(YourItemRenderer);

Filed under: ActionScript 3, Flex, How to, , , , , , , , ,

So what’s it about?

Bitesize Bugs is a collection of short articles that expose pesky bugs in front-end web technologies like JavaScript, CSS, HTML and browser behaviors gone bad.