Create a Spark item renderer in ActionScript

To ensure that your application achieves the highest performance, implement item renderers in ActionScript. Typically, you create item renderers in ActionScript only for mobile applications, but you can create them for desktop application as well.

The item renderer typically implements two interfaces:

Item renderer interface

Implemented by

Use

IDataRenderer

Item renderer

Defines the data property used to pass information to an item renderer.

At a minimum, an item renderer must implement IDataRenderer to display data.

IItemRenderer

Item renderer

Defines the APIs that a component must implement to create an item renderer that can communicate with a host component to support user interaction with the data item. User interactions include selection, dragging, and the caret indicator. For some components, such as the Spark List control, user interaction includes item selection.

Create an ActionScript item renderer in one of the following ways:

  • Create an ActionScript subclass from an existing item renderer class, such as spark.components.LabelItemRenderer, spark.components.IconItemRenderer, or spark.components.supportClasses.ItemRenderer. The existing item renderer classes already implement all necessary interfaces.

    For the highest performance in a mobile application, create a subclass of spark.components.LabelItemRenderer. In your subclass, you can control the background display and the layout of the data items.

    If you want to use the built-in Flex layout mechanism, and are not as concerned with performance, create a subclass of spark.components.supportClasses.ItemRenderer.

    For more information, see Create an ActionScript item renderer as a subclass of the LabelItemRenderer class.

    For more information on using LabelItemRenderer and IconItemRenderer, see Using a mobile item renderer with a Spark list-based control.

  • Create an ActionScript subclass of the mx.core.UIComponent class.

    By implementing an item renderer as a subclass of the UIComponent class, you can obtain the best performance because you only have to implement the logic necessary to support your application. However, basing an item renderer on UIComponent requires the most effort. To be used as an item renderer, your subclass must implement the mx.core.IDataRenderer and spark.components.IItemRenderer interfaces.

For example implementations of item renderers written in ActionScript, view the source code for the spark.components.LabelItemRenderer, spark.components.IconItemRenderer, and spark.components.supportClasses.ItemRenderer classes.