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, , , , , , , , ,

2 Responses

  1. Just what I needed – was casting to IFactory as auto-suggested by FDT, which did not help. thank you for finding and posting this!

  2. jk says:

    Good post. Thanks, saved me some time.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: