Over a million developers have joined DZone.

Decreasing startup time of a Flex 4 application using virtualization: the three rules - Part I

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

I've spent several days presenting the new Flex 4 features for many of our enterprise clients. As it's simple to understand, most of the time is dedicated to the brand-new Flex 4 List based components. 

Spark List-based components bring a lot of new topics to consider when developing Flex 4 applications: the DataGroup container, virtualization, the dropdown list, custom item rendere and more.

One cool thing about DataGroup is that it supports virtual layouts. As each time I show this topic I get many questions, I've promised myself to write some posts to explain what a virtual layout is.

DataGroup container replaces Repeater container. Taht's a good move from Adobe because the Repeater often comes up with memory leaks.

Virtual layouts allows you to create only objects that need to be shown onscreen and to recycle item renders.  So it's just a matter of how item renderer are created and handled by the layout. 

For allowing a DataGroup to recycle item renderers there are 3 requirements that must match:

1. The useVirtualLayout  property set to "true"



<HorizontalLayout useVirtualLayout="true"/>



2. At least an itemRenderer specified and none itemRendererFunction used:

 <s:DataGroup dataProvider="{ myAC }" id="dataGroup" width="100%" height="100% itemRederer="renderer.myRenderer">

3. Instead of using data binding within the item renders,  use the override of the set data (not mandatory but highly recomended):

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 





override public function set data(value:Object):void


super.data = value;

if (value== null)

myText.selected = false;

myText.text = value.firstName.toString();





<s:State name="normal"/>

<s:State name="hovered"/>

<s:State name="selected"/>


<s:Rect left="0" right="0" top="0" bottom="0">


<s:SolidColor color="0xCEDBEF" color.hovered="0xA8C6EE" color.selected="0xCCCCCC" />



<s:RichText text="{ data.firstName }" horizontalCenter="0" />


As you can easily deduct, choosing to use a virtual layout could represent a huge performance gain when your dataProvider works with many items.

I want to add more info about his topic, and I'll write a new piece of information about that soon. In the meantime have a look at this examples:

Creating a recyclable item renderer

Note that the Spark List turns on virtual layout by default.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Published at DZone with permission of Marco Casario, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}