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 http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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>

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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

3 Responses to Using the Repeater class in Flex 4

  1. lee probert says:

    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. judah says:

    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. Don says:

    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

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree