Using the Repeater class in Flex 4

The following example shows how you can use the Repeater class with Flex 4. The trick to using the Repeater class in Flex 4 is that the repeater must be within an MX container (HBox, VBox, Canvas, mx:Panel, mx:Application, etc).

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/2009/03/10/using-the-repeater-class-in-flex-gumbo/ -->
<s:Application name="Spark_Repeater_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">
 
    <fx:Declarations>
        <s:ArrayList id="arrList"
                source="[Red,Orange,Yellow,Green,Blue]"/>
    </fx:Declarations>
 
    <s:VGroup horizontalCenter="0" verticalCenter="0">
        <s:Label text="-- Start" />
 
        <mx:HBox>
            <mx:Repeater id="r" dataProvider="{arrList}">
                <s:Button left="20" top="335" label="{r.currentItem}" />
            </mx:Repeater>
        </mx:HBox>
 
        <s:Label text="Finish --" />
    </s:VGroup>
 
</s:Application>

[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 “Using the Repeater class in Flex 4

  1. Do you know if a repeater has to have a dataProvider or will the count property suffice? I’m not having any luck getting a simple repeater to add multiple children into my container in Flex 4. I don’t need a DP.

  2. Do repeaters show visually in Design View in Gumbo? I can’t seem to get the repeater content to show while in FB3 there was a preview.

    Example code,

    	<mx:VBox id="contentVBox0" verticalGap="0" left="0" y="0" width="400">
    		<mx:Repeater id="postsRepeater" dataProvider="{content1.lastResult.posts.post}" width="100%" x="0" y="0">
    			<mx:VBox id="contentVBox3" width="100%" verticalGap="0">
    				<mx:Canvas id="canvas0" width="100%" >
    					<mx:Text id="textlink0" text="Post Title" height="26" styleName="postTitle"
    						toolTip="post?postId={postsRepeater.currentItem.@id}"
    						htmlText="{postsRepeater.currentItem.@title}" fontSize="19" fontWeight="bold"/>
    					<mx:Text id="textautosize0" y="25" selectable="true" styleName="postDateCreated" text="Saturday, January 1, 2009"
    						htmlText="{postsRepeater.currentItem.dateCreated}"  fontWeight="bold"/>
    					<mx:Text id="postDescription0" width="100%" y="52" styleName="postDescription" text="Description area"
    						htmlText="{postsRepeater.currentItem.content}"/>
    				</mx:Canvas>
    				<mx:Spacer id="spacer0" height="35" />
    			</mx:VBox>
    		</mx:Repeater>
    	</mx:VBox>
    
  3. Hi,
    How do I assign an id dynamically? I’m building a form with dynamic fields and need to then read the values to send to PHP.

    Thanks

    Don

Comments are closed.