Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Using Flash Builder 4 to create Spark item renderers

by Balaji Sridhar

Balaji Sridhar
  • balajisridhar.wordpress.com

Content

  • Overview of changes to item renderers in Flex 4/Spark
  • Flash Builder 4 item renderer support
  • Customizing your item renderer
  • Where to go from here

Created

22 November 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flex Spark

Requirements

Prerequisite knowledge

Familiarity with Flex item renderers, Spark, and Flash Builder will be helpful.

User level

Intermediate

Required products

  • Flash Builder 4 (Download trial)
  • Flex 4.1 SDK

Item renderers play a significant role in building engaging Flex applications. Item renderers enable developers to customize how data is rendered by List-based components. In Flex 4 the item renderer infrastructure has evolved as part of the introduction of the Spark component and skinning architecture. Because of this, item renderers in Spark are much more intuitive and robust. Additionally, Flash Builder 4 now provides a workflow to generate custom item renderers for a supported set of Spark and MX components.

In this article, I'll detail the changes made to item renderers in Spark and how you can make use of them effectively. As part of this, I will also walk through the new-wizard based Flash Builder 4 workflow for generating item renderers.

Overview of changes to item renderers in Flex 4/Spark

Several design goals underpinned the rethinking of Spark item renderers:

  • Improve performance of the default item renderer.
  • Improve performance and usability when the developer creates an item renderer and does not want to worry about the selection/rollover background.
  • Improve performance and usability when the developer creates an item renderer and wants to change the selection shape or color with hard-coded or stylable values.
  • Make it easier to develop custom item renderers.

To achieve these objectives (among others) the following changes were made in Flex 4/Spark item renderers:

  • All of the visuals—including rollover and selection of the renderer—are now specified in the renderer itself and are not drawn by the component.
  • When you set the autoDrawBackground property on an item renderer to true (its default value) the background will be handled automatically for you. (It basically performs graphics.drawRect() behind the scenes.) To completely control the background color of an item renderer, set the autoDrawBackground property to false —then your item renderer will be responsible for displaying the background colors for all user interactions, such as selection and hovering.
  • The MXItemRenderer class (the base class for the MX component item renderer) is built on the Spark item renderer and therefore has autoDrawBackground set to true . The MXItemRenderer class is a convenience class, which allows you to use Spark-like item renderers with MX components. For example, the MX Tree and MX DataGrid components are not yet part of the Spark component architecture and thus have a different contract for item renderers. You can use the MXItemRenderer class to create Spark-like item renderers for use with the MX Tree or MX DataGrid controls. MXItemRenderer extends ItemRenderer, intercepts lifecycle events, and overrides the setting of ItemRenderer properties to handle the padding MX List-based components put around the renderer so that the states used by the renderer match the backgrounds being displayed under the renderer.

Flash Builder 4 item renderer support

Flash Builder 4 now provides support for creating and editing item renderers directly for a supported set of MX components (Tree, DataGrid and AdvancedDataGrid) and all Spark components that use item renderers. The primary intent is to help beginners jumpstart the creation of a basic, boiler-plate custom item renderer.

You can trigger this workflow from Design view, Source view, the File menu, or the Property Inspector.

From Design view

In Design view, when you right-click (Windows) or Control-click (Mac OS X) on a component that supports the itemRenderer property, Flash Builder displays a context menu item from which you can select Create Item Renderer (see Figure 1).

Select Create Item Renderer from the context menu in Design view.
Figure 1. Select Create Item Renderer from the context menu in Design view.

When you select Create Item Renderer, the New MXML Item Renderer dialog box will appear (see Figure 2).

Use the New MXML Item Renderer dialog box to create a new item renderer.
Figure 2. Use the New MXML Item Renderer dialog box to create a new item renderer.

Simply select a package, type a name for the item renderer, and click Finish. Flash Builder will generate the external item renderer code in the package you specify (see Figure 3).

Automatically generated code for an item renderer includes the Label.
Figure 3. Automatically generated code for an item renderer includes the Label.

To customize the template that is used to generate the custom item renderer file, choose Window > Preferences, select Flash Builder > File Templates, expand the MXML file type, and select Item Renderer for Spark Components.

Once you have an item renderer configured, you can open its source code by selecting the component in Design view, and selecting Open Item Renderer Declaration from the context menu (see Figure 4).

Open an existing item renderer declaration.
Figure 4. Open an existing item renderer declaration.

If you have an MX DataGrid or AdvancedDataGrid component, you can create or select an item renderer for it by selecting it and clicking Configure Columns in the Property Inspector. The Configure Columns dialog box (see Figure 5) has an Item Renderer option where you can select an existing item renderer; you can also click the button to the right to create a new item renderer.

You can create an item renderer for DataGrid and AdvancedDataGrid components using the Configure Columns dialog box.
Figure 5. You can create an item renderer for DataGrid and AdvancedDataGrid components using the Configure Columns dialog box.

From Source view

In Source view the Content Assist feature of Flash Builder 4 enables you to select an existing item renderer or create a new one when you add an itemRenderer property to a component that supports it (see Figure 6).

Use Content Assist to quickly specify an item renderer while editing code.
Figure 6. Use Content Assist to quickly specify an item renderer while editing code.

If you select an existing item renderer its name will be inserted in the code. If you select Create Item Renderer, you can use the New MXML Item Renderer dialog box to define a new one.

From the File menu

You can also create a new item renderer by choosing File > New > Other and selecting MXML Item Renderer (see Figure 7).

Expand the Flash Builder option to select MXML Item Renderer.
Figure 7. Expand the Flash Builder option to select MXML Item Renderer.

Alternatively, you can choose File > New > MXML Item Renderer (see Figure 8).

Create a new item renderer by choosing File > New > MXML Item Renderer.
Figure 8. Create a new item renderer by choosing File > New > MXML Item Renderer.

From the Property Inspector

From the Property Inspector (in Standard view), click the icon to the right of the Item Renderer setting to create a new item renderer (see Figure 9). If an item renderer has already been defined for the component, you will also see an option to open the item renderer declaration.

Click the pink icon in Standard view.
Figure 9. Click the pink icon in Standard view.
In Alphabetical view the item renderer is displayed as the value of the itemRenderer property.
Figure 10. In Alphabetical view the item renderer is displayed as the value of the itemRenderer property.

In Alphabetical view, the Value field for the property itemRenderer will display the associated item renderer for the selected component (see Figure 10).

Customizing your item renderer

The basic custom item renderer you generated (see Figure 3) will draw a highlight (or selection) background rectangle by default. To customize the appearance of the item renderer on selection or scroll you need to use states and set the autoDrawBackground property to false ; for example:

<?xml version="1.0" encoding="utf-8"?> <s:ItemRenderer focusEnabled="false" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" autoDrawBackground="false"> <s:states> <s:State name="normal" /> <s:State name="hovered" /> <s:State name="selected" /> <s:State name="normalAndShowsCaret" stateGroup="caretStates" /> <s:State name="hoveredAndShowsCaret" stateGroup="caretStates"/> <s:State name="selectedAndShowsCaret" stateGroup="caretStates"/> </s:states> <s:Rect left="0" right="0" top="0" bottom="0"> <s:stroke.caretStates> <s:SolidColorStroke color="0xFF0000" weight="1"/> </s:stroke.caretStates> <s:fill> <s:SolidColor color.normal="0xFFFFFF" color.normalAndShowsCaret="0xFFFFFF" color.hovered="0x00FF00" color.hoveredAndShowsCaret="0x00FF00" color.selected="0x0000FF" color.selectedAndShowsCaret="0x0000FF" /> </s:fill> </s:Rect> <s:Label id="labelDisplay" verticalCenter="0" left="3" right="3" top="6" bottom="4" color.hovered="green" color.selected="red"/> </s:ItemRenderer>

Once you’ve done this, you can handle the visuals of the item renderer yourself. This involves creating MXML graphics to visually present the change as the item renderer enters and exits its default states or custom states you define. 

Where to go from here

The changes made to the Flex 4 item renderer are designed to be simple and easy to follow. See the Flash Builder documentation on the Item Renderer workflow for help in getting up to speed with the tooling support for creating and editing item renderers. For more information on Flex 4 features, see the Flex 4 Features and Migration guide .

You may also want to take a look at Deepa Subramaniam's article What's new in Flex 4 and Andrew Shorten's article What's new in Flash Builder 4.

More Like This

  • Introducing Adobe Flex 4.6 SDK
  • Introducing Adobe Flex 4.5 SDK
  • Layout mirroring with Flex
  • A brief overview of the Spark architecture and component set
  • Differences between Flex 3 and Flex 4
  • Spark layouts with Flex 4

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement