What is the Difference between a custom Component and an ItemRenderer?
I've been working with D for a few months as a personal mentoring client. We chat either via e-mail or Skype and I help him with his personal growth as a programmer. He asked me this question recently on itemRenderers and custom Flex components which made me think, so I'm turning it into a post:
What is the difference between a custom component and an item renderer? Are they or can they be the same thing??
In general terms, an itemRenderer is a custom component. But, not all custom components can be used as itemRenderers.
An itemRenderer component should implement IDataRenderer interface. This gives the component a data property which the itemRenderer "generator" uses to pass in the data to be displayed.
If used in list based classes, an itemRenderer should probably also implement IDropInListItemRenderer interface and/or IListItemRenderer. The IDropInListItemRenderer interface adds the listData property, which gives you custom access to list stuff. In the Flextras AutoCompleteComboBox itemRenderers get passed a custom subclass of listData that includes the type ahead text and is used for highlighting purposes.
The IListItemRenderer is basically a bunch of UIComponent stuff with the addition of the IDataRenderer. Unless you're doing fringe Flex Development, all your itemRenderers will extend UIComponent in some manner.
These interfaces are implemented by most of the Flex controls, such as radio buttons, checkboxes, and ComboBoxes.
To give a more accurate answer, the itemRenderer property is a class factory that creates instances of the specified custom component. A factory is just a class that creates other classes, and most itemRenderers in Flex are instances of the ClassFactory. This is masked a bit in MXML, where you specify the itemRenderer value as an absolute class path, not an instance of the ClassFactory.
I couldn't decide whether to post this to my personal blog or the Flextras blog. I thought about putting it on the Flextras and posting a link from here, but that would be cheesy, right? I posted here because this blog is in the aggregators and more people read it. I do like fielding questions from the audience, so feel free to ask them or stop by a Flextras Friday Lunch session and ask me in person.
If you're really inspired to show you support check out The Flex Show's sponsorship drive, which ends in a few days.




