Passing arguments to Item Renderers in Flex

When trying to create general-purpose item renderers in Flex, one of the first things I ran into was passing arguments. Passing arguments allows you to use the same item renderer in different ways.

The best solution I’ve been able to come up with is to create my own factory class:

package com.zacharypinter.util
{
import flash.utils.Dictionary;

import mx.core.IFactory;

public class ArgumentsToRendererFactory implements IFactory
{
private var klass:Class;
private var args:*;

public function ArgumentsToRendererFactory(args:*,klass:Class) {
this.args=args;
this.klass=klass;
}

public function newInstance():*
{
var instance:Object = new klass;

for (var key:String in args) {
if (instance.hasOwnProperty(key)) {
instance[key] = args[key];
}
}

return instance;
}

}
}

To use it, you can write something like this:

In the above example, I’m using the ArgumentsToRendererFactory to pass a radio group to every item renderer. This lets me use radio buttons inside a list component

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s