Detecting the current state on a Spark List control item renderer in Flex 4

The following example shows how you can detect the current state on a Spark List control item renderer in Flex 4 by using the currentState property.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/05/15/detecting-the-current-state-on-a-spark-list-control-item-renderer-in-flex-4/ -->
<s:Application name="Spark_List_itemRenderer_currentState_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx">
 
    <s:List id="lst"
            itemRenderer="skins.CustomItemRen"
            width="200"
            horizontalCenter="0" verticalCenter="0">
        <s:layout>
            <s:VerticalLayout gap="0"
                    horizontalAlign="contentJustify"
                    requestedRowCount="6" />
        </s:layout>
        <s:dataProvider>
            <s:ArrayList source="[one,two,three,four,five,six,seven,eight,nine]" />
        </s:dataProvider>
    </s:List>
 
</s:Application>

And the custom Spark item renderer, skins/CustomItemRen.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/05/15/detecting-the-current-state-on-a-spark-list-control-item-renderer-in-flex-4/ -->
<s:ItemRenderer name="CustomItemRen"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        autoDrawBackground="true">
    <s:states>
        <s:State name="normal" />
        <s:State name="hovered" />
        <s:State name="selected" />
        <s:State name="normalAndShowsCaret" />
        <s:State name="hoveredAndShowsCaret" />
        <s:State name="selectedAndShowsCaret" />
    </s:states>
 
    <s:Label text="{itemIndex}) {currentState}"
            left="3" right="3" top="5" bottom="5" />
 
</s:ItemRenderer>

[GoogleAdsWide]

View source is enabled in the following example.

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

3 thoughts on “Detecting the current state on a Spark List control item renderer in Flex 4

  1. This example is super lame and has nothing to do with state, as the title implies, but is only a rudimentary example of binding.

  2. HI,

    i made a gallery of images using LIST and itemRenderer for images.
    but i want to change the size of few images i.e, diff from remaining images , based on scroll position.

    so can any one give me some idea how to proceed

    i guess through listData and rowIndex but i m getting an error so if any one has example or idea please share it… thnx in advance

Comments are closed.