Solved

Conditional Statement in Repeater Control

Posted on 2008-06-12
4
1,743 Views
Last Modified: 2012-05-05
Can someone post an example of embedding a conditional statement in a repeater? For example in the sample below if the currentItem is 3 change the button color to blue.



<?xml version="1.0"?>

<!-- Simple example to demonstrate the Repeater class. -->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

 

<mx:Script>

<![CDATA[

 

import mx.controls.Alert;

 

[Bindable]

private var dp:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 

 

]]>

</mx:Script>

 

<mx:Panel title="Repeater Example" width="75%" height="75%" 

paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

 

<mx:Text width="100%" color="blue" 

text="Use the Repeater class to create 9 Button controls in a 3 by 3 Tile container."/>

 

<mx:Tile direction="horizontal" borderStyle="inset" 

horizontalGap="10" verticalGap="15"

paddingLeft="10" paddingTop="10" paddingBottom="10" paddingRight="10">

 

<mx:Repeater id="rp" dataProvider="{dp}">

<mx:Button height="49" width="50" id="Button1"

label="{String(rp.currentItem)}"

click="Alert.show(String(event.currentTarget.getRepeaterItem()) + ' pressed')"/>

</mx:Repeater> 

</mx:Tile>

 

</mx:Panel> 

</mx:Application>

Open in new window

0
Comment
Question by:_CODER_
  • 3
4 Comments
 

Author Comment

by:_CODER_
ID: 21777614
bumping up the points... Just need an example please.
0
 

Author Comment

by:_CODER_
ID: 21780848
raising points again... anyone?
0
 
LVL 19

Accepted Solution

by:
Gary Benade earned 500 total points
ID: 21791447

<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

	<mx:Script>

		<![CDATA[

			import mx.core.Repeater;

			

		import mx.controls.Alert;

		 

		[Bindable] private var dp:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; 
 

		private function getColor( o:Object):uint

		{

			if( o == '3')

				return 0X0000FF;

			return 0x00FF00;			

		}		 		 

		]]>

	</mx:Script>

 

	<mx:Panel title="Repeater Example" width="75%" height="75%" 

	paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">	 

	<mx:Text width="100%" color="blue" 

	text="Use the Repeater class to create 9 Button controls in a 3 by 3 Tile container."/>	 

	<mx:Tile direction="horizontal" borderStyle="inset" 

	horizontalGap="10" verticalGap="15"

	paddingLeft="10" paddingTop="10" paddingBottom="10" paddingRight="10">	

	<mx:Repeater id="rp" dataProvider="{dp}">

	<mx:Button height="49" width="50" id="Button1" color="{getColor(rp.currentItem)}"

	label="{String(rp.currentItem)}"

	click="Alert.show(String(event.currentTarget.getRepeaterItem()) + ' pressed')"/>

	</mx:Repeater> 

	</mx:Tile>	 

	</mx:Panel> 

</mx:Application>

Open in new window

0
 

Author Closing Comment

by:_CODER_
ID: 31466798
Thank you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now