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 “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);
About these ads

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:

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: