Using the Repeater class in Flex 4

by Peter deHaan on March 10, 2009

in Repeater, beta2

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

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 beta, check out the Adobe Flash Builder 4 page on the Adobe Labs site. To download the latest build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. For instructions on using the beta Flex 4 SDK in Flex Builder 3, see "Using the beta Flex 4 SDK in Flex Builder 3".

<?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/halo">
 
    <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>

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.

{ 2 comments… read them below or add one }

1 lee probert April 30, 2009 at 9:17 am

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.

Reply

2 judah June 3, 2009 at 11:14 am

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>

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: